User`s guide
9 Managing and Sh aring Application Data in GUIDE
set(hObject,'UserData',data);
% Display new total.
set(hObject,'String',...
['You have entered an inval id entry ',...
num2str(data.number_errors),' times.']);
% Restore focus to the edit text box after error
uicontrol(hObject)
end
To update the number o f errors, the code must first retrieve the value of
the edit text
UserData property, and then it must increment the count.
Thecodethensavestheupdatederrorcountinthe
UserData property
and displays the new count.
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.
Sharing Data with Application Data
To obtain copies of the GUI files for this example, follow the steps listed
below. If you are reading this in the MATLAB H elp browser, you can access
the example FIG-file and c ode file by clicking the followin g links. If you are
reading this on the Web or in PDF form, you should go to the corresponding
section in the MATLAB H elp Browser to use the links.
If you intend to modify the layout or code of this GUI example, you should
first save copies of its code file and F IG -file to your current folder. (You need
write a ccess to your current folder to do this.) Follow these steps to copy the
example files to your current folder, and then open them:
1 Click here to copy the files to your current folder.
9-14