Error using AppDesigner attempting to output to a TextArea

1 view (last 30 days)
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
Walter Roberson
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.

Sign in to comment.

Answers (2)

Walter Roberson
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.

Eric Delgado
Eric Delgado on 7 Mar 2023
@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)
data = 2×3 table
mnr diagnosis recommendation __________ ________________ ______________ {'Eric' } {'Lowback Pain'} {'Meditation'} {'Marina'} {'Headache' } {'Tylenol' }
%% 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
rec = 2×1 string array
"Patient: Eric has a diagnosis of Lowback Pain. Side Output: Meditation" "Patient: Marina has a diagnosis of Headache. Side Output: Tylenol"
app.TextArea.Value = rec;


Find more on Tables 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!