Radio buttons in GUI
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
Andy
2015-4-18
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/
采纳的回答
更多回答(3 个)
Jan
2012-7-10
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);
0 个评论
Michael Adelman
2012-7-10
编辑:Michael Adelman
2012-7-10
3 个评论
Jan
2012-7-11
@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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!