dealing with checkbox in GUI
12 views (last 30 days)
Show older comments
Accepted Answer
Dennis
on 17 May 2019
Use a loop and uncheck/check them.
%create 20 checkboxes
for i=20:-1:1
handles.uihandles(i)=uicontrol('style','checkbox','position',[100 600-i*25 20 20]);
end
set(gcf, 'Position', get(0, 'Screensize'));
%create 1 pushbutton
uicontrol('style','pushbutton','string','check all','position',[200 600 80 40],'callback',{@check_all_callback,handles});
function check_all_callback(~,~,handles)
if handles.uihandles(1).Value==1 %if the last checkbox is checked, uncheck all
for i=1:20
handles.uihandles(i).Value=0;
end
else
for i=1:20
handles.uihandles(i).Value=1; %if the last checkbox is unchecked, check them all
end
end
end
If you are using guide/appdesigner your handles will not be indexed as in my example. In that case use sprintf to construct handle names.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!