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

1 次查看(过去 30 天)
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".

回答(1 个)

Walter Roberson
Walter Roberson 2017-1-20
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

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by