Create unkown number of checkboxes with UIControl

2 views (last 30 days)
Hi Everyone!
In my code I'm required to create a number of checkboxes according to a number of lines in a file (which varies).
I know it's highly unrecommended to create variables and of course handles in a loop, so how can I apply this? Let's say I want to create: checkbox_1, checkbox_2, ...., checkbox_i And then extract the value of each checkbox in the end?
Great thanks in advance!

Accepted Answer

Walter Roberson
Walter Roberson on 13 Aug 2015
button_strings = {'Rozencratz', 'Guildensteen', 'Top Gun', 'The Invisible Man'};
numbut = length(button_strings);
for K = 1 : numbut
button(K) = uicontrol('Style',...
'radiobutton', 'Value', 0,
'String', button_strings{K},...
'Position',[10 200+K*20 100 30]);
end
and later:
for K = 1 : numbut
buttonval(K) = get(button(K), 'Value');
end

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!