uicontrol('PropertyName',PropertyValue,...)
h = uicontrol(...)
uicontrol('PropertyName',PropertyValue,...)
is a uicontrol object creation function that accepts property name/property value pairs as input arguments. These properties are described under "Object Properties." You can also set and query property values after creating the object by using the set
and get
functions. uicontrols, or user interface controls, are useful in implementing graphical user interfaces. When selected, most uicontrol objects perform a predefined action. MATLAB supports seven styles of uicontrols, each of which is suited for a different purpose:
Check boxes also generate an action when pressed, but remain in a pressed state until pressed a second time. These objects are useful when providing the user with a number of independent choices, each toggling between two states. To activate a check box, press and release the mouse button on the object. The state of the objects is indicated on the display.
Popup menus display a list of choices when you press them. When not activated, they display a single button with text indicating their current setting. Popup menus are useful when you want to provide users with a number of mutually exclusive choices, but do not want to take up the amount of space that a series of radio buttons require.
Radio buttons are similar to check boxes, but are intended to be mutually exclusive (i.e., only one is in a pressed state at any given time). To activate a radio button, press and release the mouse button on the object. The state of the objects is indicated on the display. Note that your code must implement the mutually exclusive behavior of radio buttons.
Sliders are intended to accept numeric input by allowing the user to move a sliding bar (by pressing the mouse button and dragging the mouse over the bar) within a rectangle. The location of the bar indicates a numeric value that is selected by releasing the mouse button. You can set the minimum, maximum, and initial values of the slider.
Editable text are boxes containing editable text. After typing in the desired text, press Control-Return or move the pointer off the object to execute its Callback
. Use editable text when you want to input text.
Frames are boxes that enclose regions of a figure window. Frames can make a user interface easier to understand by grouping related controls.
These objects are children of figures and are therefore independent of axes.
h = uicontrol(...)
returns the handle of a uicontrol object.
BackGroundColor
ColorSpec reference page for more information on specifying color.ButtonDownFcn
eval
function to execute the specified function. Initially the empty matrix.CallBack
eval
function to execute the Callback
.Children
Clipping
on
(Default.) Any portion of the control outside the axes rectangle is not displayed.off
The control is not clipped.ForeGroundColor
ColorSpec reference page for more information on specifying color.HorizontalAlignment
left
Text is left-justified with respect to the uicontrol.center
(Default.) Text is centered with respect to the uicontrol.right
Text is right-justified with respect to the uicontrol.Interruptible
yes
The control callbacks (ButtonDownFcn
and Callback
) are interruptible by other callbacks.no
(Default.) The control callbacks are not interruptible.Max
Value
property. For radio buttons and check boxes, which operate as on/off switches, this represents the setting of Value
while the uicontrol is in the on
position. For popup menus, this property specifies the maximum number of choices you can define on the menu. For sliders, this property is the largest value you can select. The default maximum is 1.Min
Value
property. For radio buttons and check boxes, which operate as on/off switches, this represents the setting of Value
while the uicontrol is in the off
position. For sliders, this property is the minimum value that you can select. The default minimum is 0.Parent
Position
[left,bottom,width,height]
, that defines the size and position of the uicontrol. left
and bottom
are the distance from the lower-left corner of the figure window to the lower-left corner of the uicontrol object. width
and height
are the dimensions of the control rectangle. All measurements are in units specified by the Units
property.String
Style
pushbutton
(Default.) Push button.radio
Radio button.checkbox
Check box.slider
Slider.edit
Editable text.popup
Popup menu.Type
'uicontrol'
for a uicontrol object.Units
pixels
(Default.) Screen pixels.normalized
Normalized coordinates, where the lower-left corner of the figure maps to (0,0) and the upper-right corner to (1.0,1.0).inches
Inches.cent
Centimeters.points
Points. Each point is equivalent to 1/72 of an inch.Position
properties. All units are measured from the lower-left corner of the figure window. If you change the value of Units
, it is good practice to return it to its default value after completing your computation so as not to affect other functions that assume Units
is set to the default value.UserData
get
command.Value
Value
to Max
(usually 1) when they are on (when the button is pressed) and Min
(usually 0) when off (not pressed)Value
to the number indicated by the slider bar, relative to the range established by Min
and Max
.Value
to the index of the item selected. The "Examples" section shows how to use the Value
property to determine which item has been selected.Value
property either interactively with the mouse or through a call to the set
function. The display reflects changes made to Value
.Visible
on
(Default.) uicontrol is visible on the screen.off
uicontrol is not visible on the screen.
You can create a uicontrol object that changes figure colormaps by specifying a popup menu and supplying an M-file as the object'sh = uicontrol('Style','Pushbutton','Position',...
[20 150 100 70], 'Callback','cla','String','Clear');
Callback
:
This call tohpop = uicontrol('Style','Popup','String',...
'hsv| hot|cool|gray','Position',[20 320 100 50],...
'Callback','setmap')
uicontro
l defines four individual choices in the menu: hsv
, hot
, cool
, and gray
. You specify these choices with the String
property, separating each with the "|" character.
The Callback
, in this case setmap
, is the name of an M-file that defines a more complicated set of instructions than a single MATLAB command:
Theval = get(hpop,'Value');
if val == 1
colormap(hsv)
elseif val == 2
colormap(hot)
elseif val == 3
colormap(cool)
elseif val == 4
colormap(gray)
end
Value
property contains a number that indicates which choice you selected. The choices are numbered sequentially from one to four. The setmap
M-file can get and then test the contents of the Value
property to determine what action to take.
uimenu
(c) Copyright 1994 by The MathWorks, Inc.