User`s guide
Share Data Among a GUI’s Callbacks
• num2 str converts the value to a string.
•
set sets the String property of the edit text component to the updated
value.
Edit Text Callback. The callback for edit text,
edittext_callback,usesthe
slider handle,
sh, to determine the slider’s Max and Min properties and to set
the slider
Value property, which determine the position of the slider thumb.
The edit text callback uses the following code to s et the slider’s value to the
number that the user enters, after checking to see if it is a single numeric
value within the allowed range.
if isnumeric(va l) && length(val) = = 1 && ...
val >= get(sh,'Min') && ...
val <= get(sh,'Max')
set(sh,'Value',val);
If the value is out of range, the if statement continues by incrementing the
error counter,
number_errors, and displaying a message telling the user how
many times they have entered an invalid number.
else
number_errors = number_errors+1;
set(hObject,'String',...
['You have entered an inval id entry ',...
num2str(number_errors),' times.']);
end
Share Data with UserData
Every GUI component, and the figure itself, has a Us erData property that
you can use to store application-defined data. To access
UserData, a callback
must know the handle of the component with which a specific
UserData
property is associated.
Use the
get function to retrieve UserData,andtheset function to set it.
13-15