App designer - How to index multiple variable names?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Zane Winyard
am 10 Mär. 2021
Kommentiert: Zane Winyard
am 16 Mär. 2021
Hello, i am trying to build a game of Mastermind in matlab app designer.
I have 40 lamps arrainged in 4 columns, and i would like to put them into a cell matrix to referance them more easily to manipulate them. This way i would only have 6 if statements instead of 40 just for changing their color, but i cannot figure out how to do this.
Making a global variable lamps = {lamp_1, lamp_2, lamp_3 etc. or {app.lamp_1, app.lamp_2, etc. doesn't seem to work.
I've tried naming them L101, L102, L201, L202 and trying app.(['L'+num2str('index')]).color = app.white; to no avail.
Anyone know how to do this better?
0 Kommentare
Akzeptierte Antwort
Mohammad Sami
am 10 Mär. 2021
You should add a private property called AllLamps. Then add startupFcn to define this property.
% Code that executes after component creation
function startupFcn(app, varargin)
app.AllLamps = {app.Lamp app.Lamp2 app.Lamp3 app.Lamp4;...
app.Lamp5 app.Lamp6 app.Lamp7 app.Lamp8};
end
The you can use it to change the "Color" property as follows.
function ButtonPushed(app, event)
row = 2;
col = 2;
app.AllLamps{row,col}.Color = 'red';
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!