필터 지우기
필터 지우기

How can I change the state of multiple CheckBoxes in App designer?

조회 수: 3 (최근 30일)
Rafael Campos
Rafael Campos 2018년 10월 27일
답변: Voss 2023년 12월 21일
I am working on a GUI that has 200 checkboxes. They have tags like "app.CheckBox_X_Y", where X can have values from 1 to 50 and Y can have values from 1 to 4.
I'd like to change the state of the last checkbox and this must change the state of all others at once.
I tried the following code, but it's giving me error "Error using set - Invalid handle". Can someone help me?
function CheckBoxPelota_X_1ValueChanged(app, event)
if app.CheckBoxPelota_X_1.Value == 0
for cont1 = 1:1:50
for cont2 = 1:1:4
set(sprintf('app.CheckBoxPelota_%d_',cont1),'Value', 1);
end
end
else
for cont1 = 1:1:50
for cont2 = 1:1:4
set(sprintf('app.CheckBoxPelota_%d_',cont1),'Value', 0);
end
end
end
end

채택된 답변

Voss
Voss 2023년 12월 21일
I'll assume that the description, "tags like "app.CheckBox_X_Y", where X can have values from 1 to 50 and Y can have values from 1 to 4", is accurate, that CheckBoxPelota_X_1ValueChanged is the ValueChangedFcn of the top-most "Marcar Todos" checkbox, that that checkbox's tag is CheckBoxPelota_X_1, and that (un)checking it should set the Value of all other checkboxes in the top row to match the Value of app.CheckBoxPelota_X_1 and not effect the checkboxes in the other three rows.
function CheckBoxPelota_X_1ValueChanged(app, event)
val = app.CheckBoxPelota_X_1.Value;
for cont1 = 1:50
set(app.(sprintf('CheckBox_%d_1',cont1)),'Value',val);
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by