| 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, the previous slider value previous_val, and the new slider value val. There is no need to pass these variables as arguments. Both callbacks use the input argument hObject to getand setpropertiesof the component that triggered execution of the callback. This argument is available to the callbacks because the components' Callback properties are specified as function handles. See "Associating Callbacks with Components" on page 12-12 for more information. Slider Callback. The slider callback, slider_callback,usesthe edit text component handle, eth,toset theedittext 'String ' property to the value 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: • The get command obtains the current value of the slider. • The num2str command converts the value to a string. • The set command sets the String property ofthe edit text component to the updated value. |