How do I create loop, where conditions equal pushed radio buttons?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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".
0 comentarios
Respuestas (1)
Walter Roberson
el 20 de En. de 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
0 comentarios
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!