App designer - How to index multiple variable names?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zane Winyard
el 10 de Mzo. de 2021
Comentada: Zane Winyard
el 16 de Mzo. de 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 comentarios
Respuesta aceptada
Mohammad Sami
el 10 de Mzo. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!