Error using AppDesigner attempting to output to a TextArea
Show older comments
Hello,
I am trying to build an app that automates a decision tree to output a patient treatment recommendation based on data in an Excel spreadsheet.
I would greatly appreciate any help I can get to address the following error on the code below:
Error using matlab.ui.control.TextArea/set.Value
'Value' must be a character vector, or a 1-D array of the following type: cell array of character vectors, string, or categorical.
Error in FreemanMillerKneeTreatmentDecisionTreeApp2/FreemanMillerFootDecisionTreeButtonPushed (line 1189)
app.OutputTextArea.Value{i+1} = recommendation; %this writes each rec to a new row in the 'Output' window
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
c = ['Patient: ', mrn, 'has a diagnosis of ', diagnosis, '. ', trial,' ', side, ' Side Output: ', warning, recommendation, ' ']; %this creates a string array
ca = cellstr(c); %this converts the string array to a cell array
rec = join(ca); % join the cell array of strings into one string
app.OutputTextArea.Value{i+1} = rec; %this writes each rec to a new row in the 'Output' window
4 Comments
Eric Delgado
on 7 Mar 2023
You should put a breakpoint in this line of code (1189). Run your app and when the app stop, use the Matlab prompt to check the class of the data you are trying to put on this TextArea object.
>> class(MyDataThatIAmTryingToPutInTheObject)
It looks like you are trying to set a value that its class is different than "character vector, or a 1-D array of the following type: cell array of character vectors, string, or categorical".
Adam Graf
on 7 Mar 2023
Adam Graf
on 7 Mar 2023
Walter Roberson
on 7 Mar 2023
As a style note, I do not recommend using [] with '' literals and variables to create something that must specifically be a string array. What if the variables turned out to be character vectors in some flow paths? You are more robust to use "" strings as then the variables will be converted to string if needed, and the people reading your code do not need to go back and verify all flow paths to be sure that in every case at least one of the variables would be string.
Answers (2)
Walter Roberson
on 7 Mar 2023
app.OutputTextArea.Value{i+1} = rec;
your rec is a cell, and the destination is the contents of a cell. The Value would not end up as a cell of character vectors, it would end up as a cell of cells of character vectors.
@Adam Graf, you don't really need this loop. Try this...
mnr = {'Eric'; 'Marina'};
diagnosis = {'Lowback Pain'; 'Headache'};
recommendation = {'Meditation'; 'Tylenol'};
data = table(mnr, diagnosis, recommendation)
%% Instead of:
% c = ['Patient: ', mrn, 'has a diagnosis of ', diagnosis, '. ', trial,' ', side, ' Side Output: ', recommendation, ' \n'];
% ca = cellstr(c);
% rec = join(ca);
% app.OutputTextArea.Value{i+1} = rec;
%% Try this:
rec = "Patient: " + data.mnr + " has a diagnosis of " + data.diagnosis + ". Side Output: " + data.recommendation
app.TextArea.Value = rec;

Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!