Creating Graphical User Interfaces    

Radio Buttons

Radio buttons are similar to check boxes, but are intended to be mutually exclusive within a group of related radio buttons (i.e., only one button is in a 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:

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 GUI 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 cleared.

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.

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:

After setting the radio buttons to the appropriate state, the callback can continue with its implementation-specific tasks.


  Toggle Buttons Check Boxes