User`s guide

8 Programming a GUIDE GUI
If the edit text Max and Min properties are set such that Max - Min > 1,the
user can enter m ultiple lines. For example, setting
Max to 2, with the default
value of
0 for Min, e nables users to enter multiple lines.
Retrieving Numeric Data from an Edit Text Component
MATLAB software returns the value of the edit text St ring property as a
character string. If you want users to enter numeric values, you must convert
the characters to numbers. You can do this using the
str2double command,
which converts strings to doubles. If the user enters nonnumeric characters,
str2double returns NaN.
You can use the following code in the edit text callback. It gets the value of
the
String property and converts it to a double. It then checks whether the
converted value is
NaN (i snan ), indicating the user entered a nonnumeric
character and displays an error dialog (
errordlg).
function editte xt1_ Callback(hObject, e vent data, handles)
user_entry = str2double(get(hObject,'string'));
if isnan(use r_en try)
errordlg('You must enter a numeric value','Bad Input','modal')
uicontrol(hObject)
return
end
% Proceed with callback...
Edit text controls lose focus when the user c ommits and edit (by typing
Return or clicking away). The line
uicontrol(hObject) restores focus to the
edit text box. Although doing this is not needed for its callback to work, it is
helpful in the event that user input fails validation. The com mand has the
effect of selecting all the text in the edit text box.
Triggering Callback Execution
If the contents of the edit text component have been changed, clicking inside
the GUI but outside the edit text causes the edit text callback to execute. The
user can also press Enter for an edit text that allows o nly a single line of text,
or Ctrl+Enter foranedittextthatallowsmultiplelines.
8-34