How can i select (check off) multiple checkboxes?

13 ビュー (過去 30 日間)
Mihai
Mihai 2012 年 10 月 26 日
コメント済み: Rafael Campos 2018 年 10 月 27 日
I am working on a GUI that has a lot of checkboxes. I'd like to the user to be able to press a button that selects all of them at once.
The tags of the checkboxes are chk1, chk2, chk3...
I tried something similar to the following code, but it's giving me an error...
for i = 1:5
set(sprintf('handles.chk%d',i),'value', 1)
end
  2 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 10 月 26 日
Is this GUI made in GUIDE?
Mihai
Mihai 2012 年 10 月 26 日
Yeah it is

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 26 日
編集済み: Azzi Abdelmalek 2012 年 10 月 26 日
for ii = 1:5
set(handles.(sprintf('chk%d',ii)),'value', 1)
end
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 26 日
Thanks Matt
Rafael Campos
Rafael Campos 2018 年 10 月 27 日
Hi Azzi!
I am working on a GUI on app Designer 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
0 Comments

サインインしてコメントする。

その他の回答 (1 件)

Evan
Evan 2012 年 10 月 26 日
編集済み: Evan 2012 年 10 月 26 日
If you want to avoid using a for loop, the following functions might be useful:
help findobj
help regexp
Assuming that all your wanted checkboxes have tags of the form chkn where n = 1,2,3... and assuming there are no other checkboxes with tags of the form chkn that you want to exclude, I believe the following will set the values of all your checkboxes to 1 at once:
set(findobj('Style','checkbox','-regexp','Tag','chk[0-9]'),'Value',1)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by