Matrix of buttons in AppDesigner
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bárbara Matos
am 15 Nov. 2021
Kommentiert: Bárbara Matos
am 20 Nov. 2021
I would like to have a matriz of buttons where I can use all of this buttons. I tried someting like this (first print), but it doesn't work because I can use . in this type of variables.
I tried other option, which is in the second foto. This works and do what I want. It creates a matrix of buttons. But then, in other functions, I want to disable all of the buttons and I can't do it because I can't use an array, like in the first foto. Is there a way to use an array of buttons like in my first foto?
One example is my third foto. I want to disable all of the buttons in a for cicle, but it doesn't work because I can't use the array. In my code, if my matrix was 3x3, it only disable the last button (last image).
I wish I explain well what is my problem.
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 15 Nov. 2021
First, see this answer. The summary is it is often better to arrange everything on the canvas ahead of time, and then change the visibility of the components as needed rather than trying to do it dynamically.
As for your particular issue, you need to keep the datatype a structure in order to preserve the object handle. When you use array indexing, you loose that. A workaround is to split i and j over two different fields. This is an adaptation of what you shared.
% Value changed function: CheckBox
function CheckBoxValueChanged(app, event)
m=1;
n=2;
a=10;
b=350;
for i = 1:m
for j=1:n
app.buttonsArray(i).button(j) = uibutton(app.UIFigure,'push');
app.buttonsArray(i).button(j).Position = [a+(j-1)*60 b-(i-1)*60 55 55];
app.buttonsArray(i).button(j).Text = sprintf("Antenna\n%d, %d",i,j);
end
end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing 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!