Specifications
1 Getting Started with GUIDE
1-28
selected state at any given time). To activate a radio button, click the mouse
button on the object. The display indicates the state of the button.
Implementing Mutually Exclusive Behavior
Radio buttons have two states – selected and not selected. You can query and
set the state of a radio button through its
Value property:
•
Value = Max, button is selected.
•
Value = Min, button is not selected.
To make radio buttons mutually exclusive within a group, the callback for each
radio button must set the
Value property to 0 on all other radio buttons in the
group. MATLAB sets the
Value property to 1 on the radio button clicked by the
user.
The following subfunction, when added to the application M-file, can be called
by each radio button callback. The argument is an array containing the
handles of all other radio buttons in the group that must be deselected.
function mutual_exclude(off)
set(off,'Value',0)
Obtaining the Radio Button Handles. The handles of the radio buttons are available
from the
handles structure, which contains the handles of all components in
the GUI. This structure is an input argument to all radio button callbacks.
The following code shows the call to
mutual_exclude being made from the first
radio button’s callback in a group of four radio buttons.
function varargout = radiobutton1_Callback(h,eventdata,handles,varargin)
off = [handles.radiobutton2,handles.radiobutton3,handles.radiobutton4];
mutual_exclude(off)
% Continue with callback
.
.
.
After setting the radio buttons to the appropriate state, the callback can
continue with its implementation-specific tasks.