User`s guide
13 Manage Application-Defined Data
num2str(number_errors),' times.']);
val = previous_val;
end
end
end
Because the components are constructed at the top level, their handles are
immediately available to the callbacks that are nested at a lower level of the
routine. The same is true of the error counter,
number_errors,theprevious
slider value,
previous_val, and the new slider value, val. You do not n eed to
pass these variables as arguments.
Both callbacks use the input argument
hObject to get and set p roperties of
the component that triggered execution of the callback. This argument is
available to the callbacks because the com ponents’
Callback properties are
specified as function handles. For more information, see “Specify Callbacks in
Function Calls” on page 12-11.
Slider Callback. The slider callb ack,
slider_callback,usestheedittext
component handle,
eth,tosettheedittext'St ring' property to the value
that the user typed.
The slider
Callback saves the previous value, val, of the slider in
previous_val before assigning the new value to val. These variables are
known to both callbacks because they are initialized at a higher level. They
can be retrieved and set by either callback.
previous_val = val;
val = get(hObject,'Value');
The following statements in the slider callback update the value displayed
in the edit text component when a user moves the slider and releases the
mouse button.
val = get(hObject,'Value');
set(eth,'String',num2str(val));
The code combines three commands:
•
get obtains the current value of the slider.
13-14