Radio buttons in GUI
Mostrar comentarios más antiguos
HI,
I have two radio buttons in GUI. I want to make that only one button can be pressed at a time. what is the best way do it?
thanks,
1 comentario
Andy
el 18 de Abr. de 2015
A Button Group panel is the best way make button selections exclusive. Here is a tutorial on how to do it: https://codemusician.wordpress.com/2013/03/15/gui-tutorial-how-to-create-and-use-radio-button-groups-in-matlab/
Respuesta aceptada
Más respuestas (3)
Jan
el 10 de Jul. de 2012
I prefer to control this manually:
handles.FigureH = figure;
handles.radio(1) = uicontrol('Style', 'radiobutton', ...
'Callback', @myRadio, ...
'Units', 'pixels', ...
'Position', [10, 10, 80, 22], ...
'String', 'radio 1', ...
'Value', 1);
handles.radio(2) = uicontrol('Style', 'radiobutton', ...
'Callback', @myRadio, ...
'Units', 'pixels', ...
'Position', [10, 40, 80, 22], ...
'String', 'radio 2', ...
'Value', 0);
...
guidata(handles.FigureH, handles);
And the callback:
function myRadio(RadioH, EventData)
handles = guidata(RadioH);
otherRadio = handles.radio(handles.radio ~= RadioH);
set(otherRadio, 'Value', 0);
Michael Adelman
el 10 de Jul. de 2012
0 votos
Michael Adelman
el 10 de Jul. de 2012
Editada: Michael Adelman
el 10 de Jul. de 2012
3 comentarios
Honglei Chen
el 10 de Jul. de 2012
The following code worked well for me, I cannot get multiple selection.
h = uibuttongroup('Units', 'pixels');
% Create three radio buttons in the button group.
u0 = uicontrol('Style','Radio','String','Analog_Input',...
'pos',[19 75 137 52],'parent',h,'HandleVisibility','off');
u1 = uicontrol('Style','Radio','String','Function_input',...
'pos',[19 31 131 57],'parent',h,'HandleVisibility','off');
Michael Adelman
el 11 de Jul. de 2012
Jan
el 11 de Jul. de 2012
@Micheal: Please read the instructions for formatting code in this forum. E.g. the "About Matlab Answers" would be a good point to start from.
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!