MATLAB App Designer - Reading Data
Show older comments
Hi, I'm back. This is quite a long question so I'll try my best and include as much info as I can to get the question across. In a Matlab script, I have the matrix final_unshuffled has an order, with easy being the first row, medium being the second row, hard being the third row, and expert being the fourth. I have another matrix called FINAL_Shuffled_Columns which is 'imported' or 'read' (I'm not sure what the technical term is) which is read by an app I have which uses a .Text command to replace the button names with the string names of FINAL_Shuffled_Columns, See Below:
%NB: This is under my Start-Up Function:
function StartUp(app)
MATRIX_VALUES();
mybuttons = [app.Button1,app.Button2,app.Button3,app.Button4,...
app.Button5,app.Button6,app.Button7,app.Button8,...
app.Button9,app.Button10,app.Button11,app.Button12,...
app.Button13,app.Button14,app.Button15,app.Button16];
str = string(FINAL_Shuffled_Columns);
for i = 1:numel(mybuttons)
mybuttons(i).Text = str(i);
end
end
Later on in the code, I want to reference another matrix from the same script called final_unshuffled (See below). However, when I try to run this I get an error saying I have to explicity initialize finalUnshuffled, which means rowAsStrings doesn't get recognized correctly. I don't understand because both FINAL_Shuffled_Columns and final_unshuffled are in the same file? So how could one get read but the other one, not? I tried adding final_unshuffled as a property as well and that didn't work.
MATRIX_VALUES();
selectedButtons = [app.Button1.Text, app.Button2.Text, app.Button3.Text,...
app.Button4.Text, app.Button5.Text, app.Button6.Text, app.Button7.Text,...
app.Button8.Text, app.Button9.Text, app.Button10.Text, app.Button11.Text,...
app.Button12.Text, app.Button13.Text, app.Button14.Text, app.Button15.Text,...
app.Button16.Text];
rowAsStrings = arrayfun(@(idx) strjoin(string(app.finalUnshuffled(idx, :)), " "), 1:4, 'UniformOutput', false);
for i = 1:length(rowAsStrings)
if all(ismember(selectedButtons, strsplit(rowsAsStrings{i})))
switch i
case 1 %EASY
setColor(app, selectedButtons, 'yellow');
case 2 %MEDIUM
setColor(app, selectedButtons, 'green');
case 3 %HARD
setColor(app, selectedButtons, 'blue');
case 4 %EXPERT
setColor(app, selectedButtons, 'purple');
end
break;
end
end
SORRY FOR THE LONG QUESTION, I'D GLADLY EXPLAIN IF MORE INFO IS NEEDED. THANK YOU IN ADVANCE
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown 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!