Matrix of buttons in AppDesigner

10 Ansichten (letzte 30 Tage)
Bárbara Matos
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.

Akzeptierte Antwort

Cris LaPierre
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
  1 Kommentar
Bárbara Matos
Bárbara Matos am 20 Nov. 2021
Thank you very much. I will try adapt my code like you suggested

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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!

Translated by