Matlab App Designer - Output to TextArea Error - 'Value' must be a character vector, or a 1-D array of the following type: cell array of character vectors, string, or categori
30 views (last 30 days)
Show older comments
Hello,
I am trying to build an App that takes in data froman Excel spreadsheet and then outputs a classification of each row of that data in a TextArea.It was working until I added an 'if' statement that asked the user to select the unique rows that they wanted to classify. I don't understand the connection between the 'if' statement and the error but if I comment the 'if' statement out the code works again. I would greatly appreciate any help.
Here is the error message:
'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 GaitAnalysisApp/GaitDeviationClassificationButtonPushed (line 1267)
app.ClassificationTextArea.Value{i+1} = classification; %this writes each rec to a new row in the 'Output' window
Here is the code:
properties (Access = public)
properties (Access = public)
data % the data imported from the spreadsheet to share for all of the callbacks
rows % the number of rows in the imported spreadsheet
selectedGcdFiles % an index of the selected GcdFiles from the imported data
end
% Get unique values in the 'GcdFile' column
uniqueValues = unique(app.data.GcdFile);
% Create a pop-up window with a list that allows the user to select the GcdFiles to use
[selectionIndex,ok] = listdlg('PromptString','Select the GcdFiles to use:', 'SelectionMode','multiple', 'ListString',cellstr(uniqueValues));
% Get the selected GcdFiles
app.selectedGcdFiles = uniqueValues(selectionIndex);
for i = 1:app.rows
%Define Variables here
side = string(app.data.MotionParams_Side(i));%set the side variable to Left or Right string
trial = string(app.data.GcdFile(i));
if ismember(trial, app.selectedGcdFiles) %checks to make row of data is one that was selected
%do the classification steps here
transclass = string(transclass);
transclass = join(transclass);
c = [trial,' ', side, ' ',"Sagittal Plane: ", sagclass, '. ',"Transverse Plane: " transclass]; %this creates a string array
ca = cellstr(c); %this converts the string array to a cell array
classification = join(ca); % join the cell array of strings into one string and then convert to characters
classification = char(classification);
app.ClassificationTextArea.Value{i+1} = classification; %this writes each rec to a new row in the 'Output' window
end
end
0 Comments
Answers (1)
dpb
on 6 Apr 2023
app.ClassificationTextArea.Value{i+1} = classification;
tries to address the .Value property as a cell array which it doesn't support.
app.ClassificationTextArea.Value = classification;
but you'll have to first create the updated array of rows desired and then update the control with that new data.
You CAN manipulate the content of the control as a cell array in memory and insert/delete specific cells in it, then rewrite the update cell array.
I didn't try to read the code in detail to figure out what you're doing, specifically, but given a set of strings as a string array that want to select a subset of, I'd do something more like
ia=ismember(trial, app.selectedGcdFiles); % the subset wanted logical vector
app.ClassificationTextArea.Value = app.selectedGcdFiles(ia); % output those
You'll want/need to modify the text to display into its array format first using (ia) to address the pieces wanted, of course, but the above will show/update the user-selected list.
Doing as above will let you eliminate the for...end loop and use MATLAB logical addressing instead as its designed to be.
7 Comments
dpb
on 18 Apr 2023
Edited: dpb
on 18 Apr 2023
That looks nothing like the orignal context that you said was the problem...
I uncommented that if....end block and ran the app; no idea what am doing but I selected the first and then all the files in the dropdown list and clicked every button on the LH side and all did something and got no errors.
However, the file is simply replete with warnings of bad code constructs -- you need to go through and systematically eliminate virtually all of those issues -- there are a lot of bad string comparison syntax -- using "==" to compare a character string is replete with issues --
var='left'
var=='left'
returns an array, NOT a single logical value. It turns out in this case to still be True because each and every value in the array is true, but that's risky coding at best. Only the string class is
var="left"
var=='left'
If the variable is of the string class, THEN you can use "=="; it is designed to support it. Otherwise use
var='left';
strcmp(var,'left') % use the string comparison functions
matches(var,'left') % or newer string class extensions
Really need to just begin at the beginning of the file and start working your way through the issues...there are also a zillion places where either local variables are created and never used or references are made to what appear to be intended to be the controls but do not reference the app structure and so are just local variables of no other connection to anything. Those should all disappear either by just being completly removed if they're really not needed or by referencing the proper object or application property.
It's highly likely your app is going to remain very fragile with lots of unexplained and unexplainable behavior until these things are cleaned up. But, I couldn't reproduce your symptom with the provided code.
See Also
Categories
Find more on Develop Apps Using App Designer 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!