Matrix of buttons in AppDesigner

조회 수: 10 (최근 30일)
Bárbara Matos
Bárbara Matos 2021년 11월 15일
댓글: Bárbara Matos 2021년 11월 20일
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.

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 11월 15일
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
Bárbara Matos
Bárbara Matos 2021년 11월 20일
Thank you very much. I will try adapt my code like you suggested

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by