
Examples: Programming GUI Components
8-27
For radio buttons and toggle buttons that are managed by a button group, you
must include the code to control them in the button group’s
SelectionChangeFcn callback function, not in the individual component
Callback functions. A button group overwrites the Callback properties of
radio buttons and toggle buttons that it manages.
This example of a
SelectionChangeFcn callback uses the Tag property of the
selected object to choose the appropriate code to execute.
function uibuttongroup1_SelectionChangeFcn(hObject,eventdata,handles)
switch get(hObject,'Tag') % Get Tag of selected object
case 'radiobutton1'
% Code for when radiobutton1 is selected goes here.
case 'radiobutton2'
% Code for when radiobutton2 is selected goes here.
% Continue with more cases as necessary.
end
Note For a button group, contrary to the automatically generated comment,
hObject is the handle of the selected radio button or toggle button, and not the
handle of the button group. Use
handles.uipaneln as the handle of the button
group, where
uipaneln is the Tag of the button group.
The code above refers to the handle of
uipanel1 rather than the handle of
uibuttongroup1, because a button group is a kind of panel.
Axes
Axes components enable your GUI to display graphics, such as graphs and
images. This topic provides two examples:
• “Plotting to a GUI with a Single Axes” on page 8-27
• “Plotting to a GUI with Multiple Axes” on page 8-29
Plotting to a GUI with a Single Axes
If a GUI contains only one axes, MATLAB automatically generates the plot in
that axes.
In most cases, you create a plot in an axes from a callback that belongs to some
other component in the GUI. For example, pressing a button might trigger the
Comentarios a estos manuales