User`s guide

12 Code a Programmatic GUI
The button group Sele ctionChangeFcn callback is called whenever a selection
is made. If you have a button group that contains a set of radio buttons and
toggle buttons and you want:
An imm ediate action to occur when a radio button or toggle b utton is
selected, you must include the code to control the radio and toggle buttons
in the button group’s
SelectionChangeFcn callback function, not in the
individual togg le button
Callback functions. “Color Palette” on page 1 5-51
provides a practical example of a
SelectionChangeFcn callback.
Another component such as a push button to base its action on the
selection, then that component’s
Callback callback can get the handle
of the selected radio button or toggle button from the button group’s
SelectedObject property.
Program a Button Group. This example of a
SelectionChangeFcn callback
uses the
Tag property of the selected object to choose the appropriate code to
execute. The
Tag property of each component is a string that identifies that
component and must be unique in the GUI.
function uibuttongroup1_S electionChangeFcn(hObject,eventdata)
switch get(eventda ta.NewValue,'Tag') % Get Tag of selected object.
case 'radiobutton1'
% Code for when radiobutton1 is selected.
case 'radiobutton2'
% Code for when radiobutton2 is selected.
case 'togglebutton1'
% Code for when togglebutton1 is selected.
case 'togglebutton2'
% Code for when togglebutton2 is selected.
% Continue with more cases as necessary.
otherwise
% Code for when there is no match.
end
The hObject and eventda ta arguments are available to the callback only if
the value of the callback property is specified as a function handle. See the
SelectionChangeFcn property on the Uibuttongroup Properties reference
page for information about
eventdata.Seetheuibuttongroup reference page
and “Color Palette” on page 15-51 for other examples.
12-30