Error using AppDesigner attempting to output to a TextArea
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 7 de Mzo. de 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.
Respuestas (2)
Walter Roberson
el 7 de Mzo. de 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.
0 comentarios
Eric Delgado
el 7 de Mzo. de 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)
%% 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;
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!