Specifications
4 Programming GUIs
4-10
Note If you have radio buttons that are managed by a button group
component, you must include the code to control them in the button group’s
SelectionChangeFcn callback function, not in the individual radio button
Callback functions. A button group overwrites the Callback properties of
radio buttons and toggle buttons that it manages. See “Button Groups” on
page 4-13 for more information.
Check Boxes
You can determine the current state of a check box from within its callback by
querying the state of its
Value property, as illustrated in the following
example:
function checkbox1_Callback(hObject, eventdata, handles)
if (get(hObject,'Value') == get(hObject,'Max'))
% then checkbox is checked-take approriate action
else
% checkbox is not checked-take approriate action
end
Edit Text
To obtain the string a user typed in an edit box, get the String property in the
callback.
function edittext1_Callback(hObject, eventdata, handles)
user_string = get(hObject,'string');
% proceed with callback...
For example, setting Max to 2, with the default value of 0 for Min, enables users
to select multiple lines
Obtaining Numeric Data from an Edit Text Component
MATLAB returns the value of the edit text String 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.