User`s guide

9 Managing and Sh aring Application Data in GUIDE
The set command sets the String property of the edit text to the
updated value.
3 Set the slider value from the edit text component’s callback. The edit tex t
component’s callback sets the slider’s value to the number the user enters,
after checking to see if it is a single numeric value between 0 and 1. If the
value is out of range, the error count increments and the edit text displays a
message telling the user how many times they entered an i nvalid number.
Becausethiscodeappearsintheedittextcomponentscallback,
hObject is
the handle of the edit text component:
val = str2double(get(hObject,'Stri ng'));
% Determine whether val is a number between 0 and 1.
if isnumeric (val ) && length(val)==1 && ...
val >= get(handles.slider1,'Min ') && ...
val <= get(handles.slider1,'Max ')
set(handles.slider1,'Value',val);
else
% Increment the error count, and display it.
handles.number_errors = handles .number_errors+1;
guidata(hObject,handles); % Sto re the changes.
set(hObject,'String',...
['You have entered an inval id entry ',...
num2str(handles.number_errors),' times.']);
% Restore focus to the edit text box after error
uicontrol(hObject)
end
hObject
is the handle of the edit text component because this code appears in
the e dit text callback. The next-to-last line of the callback
uicontrol(hObject)
is useful, although not necessary for the callback to work properly. The call
to
uicontrol has the effect of placing the edit text box in focus. An edit text
control executes its callback after the user presses Return or clicks away
from the control. These actions both causetheedittextboxtolosefocus.
Restoring focus to it in the event of an error helps the user to understand
what action triggered the error. The user can then correct the error by typing
againintheedittextbox.
9-20