Matrix of buttons in AppDesigner
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bárbara Matos
le 15 Nov 2021
Commenté : Bárbara Matos
le 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 commentaires
Réponse acceptée
Cris LaPierre
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!