User`s guide
13 Manage Application-Defined Data
The GUI behavior is as follows:
• When a user moves the slider, the edit text component displays the slider’s
current value and prints a message to the Com mand Window indicating
how far the slider moved from its previous position.
You changed the slider value b y 24.11 percent.
• When a user types a value into the edit text component and then presses
Enter or clicks outside the component, the slider also updates to the value
entered and the edit te xt compo nent p rints a message to the Command
Window indicating how m any units the slider moved.
• If a user enters a value in the edit text component that is out of range for
the slider—that is, a value that is not between the slider’s
Min and Max
properties—the application returns a message in the edit text indicating
how m any times the user has entered an erroneous value.
The following code constructs the components, initializes the error counter,
and the previous and n ew slider values in the initialization section of the
function, and uses two callbacks to implement the interchange between the
slider and the edit text component. The slider callback a nd text edit callback
are nested w ithin the main function.
Copy the following code listing, paste it into a new file, and save it in
your current folder or elsewhere on your path as
slider_gui_nested.m.
Alternatively, click here to place
slider_gui_nested.m in your current
folder. Run the function by typing
slider_gui_nested at the command line.
function slider _gui _nested
fh = figure('Position',[250 250 350 350],...
'MenuBar','none','NumberTitle','off', ...
'Name','Sharing Data with Nested Functions');
sh = uicontrol(fh,'Style','slid er',...
'Max',100,'Min',0,'Value',25,...
'SliderStep',[0.05 0.2],...
'Position',[300 25 20 300],...
13-12