How do I create loop, where conditions equal pushed radio buttons?

1 view (last 30 days)
Hello, I want my program to have certain values that will be chosen based on "ticked" radio buttons. For example if option 1 was chosen, first variable equals 10, for second option variable equals 5 and so on. I'm using "if statement".

Answers (1)

Walter Roberson
Walter Roberson on 20 Jan 2017
Example adapted from the uibuttongroup documentation:
bg = uibuttongroup('Visible','off',...
'Position',[0 0 .2 1];
% Create three radio buttons in the button group.
r1 = uicontrol(bg,'Style',...
'radiobutton',...
'String','10',...
'Position',[10 350 100 30],...
'HandleVisibility','off');
r2 = uicontrol(bg,'Style','radiobutton',...
'String','5',...
'Position',[10 250 100 30],...
'HandleVisibility','off');
r3 = uicontrol(bg,'Style','radiobutton',...
'String','17',...
'Position',[10 150 100 30],...
'HandleVisibility','off');
set(bg, 'SelectedObject', []);
Then at the time you want to know what the value is:
sel = get(bg, 'SelectedObject');
if isempty(sel)
warndlg('You have not selected a value yet!');
else
sel_str = get(sel, 'String');
sel_value = str2double(sel_str);
... now use sel_value in your computation
end

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!