Specifications
User Interface Controls
1-29
Checkboxes
Check boxes generate an action when clicked and indicate their state as
checked or not checked. Check boxes are useful when providing the user with
a number of independent choices that set a mode (e.g., display a toolbar or
generate callback function prototypes).
The
Value property indicates the state of the check box by taking on the value
of the
Max or Min property (1 and 0 respectively by default):
•
Value = Max, box is checked.
•
Value = Min, box is not checked.
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(h,eventdata,handles,varargin)
if (get(h,'Value') == get(h,'Max'))
% then checkbox is checked-take approriate action
else
% checkbox is not checked-take approriate action
end
Edit Text
Edit text controls are fields that enable users to enter or modify text strings.
Use edit text when you want text as input. The
String property contains the
text entered by the user.
To obtain the string typed by the user, get the
String property in the callback.
function edittext1_Callback(h,eventdata,handles,varargin)
user_string = get(h,'string');
% proceed with callback...
Obtaining Numeric Data from an Edit Test 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 non-numeric characters,
str2double returns NaN.