User`s guide

Examples: Program GUI C omponents
slider_value = get(hObject,'Value');
% Proceed with callback...
The Max an d Min properties specify the slider’s maximum and minimum
values. The slider’s range is
Max - Min. hObject is the handle of the
component for which the event was triggered.
Toggle Button
The callback for a toggle button needs to query the toggle button to determine
what state it is in. MATLAB software sets the
Value property equal to the
Max property when the toggle button is pressed (Max is 1 by default). It sets
the
Value property equal to the Min property when the toggle button is not
pressed (
Min is 0 by default).
The following code illustrates how to program the callback in the GUI code file.
function toggle butt on1_Callback(hObject,ev entdata)
button_state = get(hObject,'Value');
if button_st ate == get(hObject,'Max')
% Toggle button is pressed-tak e appropriate action
...
elseif butto n_st ate == get(hObject, 'Min ')
% Toggle button is not pressed-take appropria te action
...
end
hObject
is the handle of the component for which the event was triggered.
You can also change the state of a toggle button programmatically by setting
thetogglebutton
Value property to the value of the Max or Min property.
For example,
set(tbh,'Value','Max')
puts the toggle b utton with handle tbh in the pressed state.
12-27