| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
handle = uicontrol('PropertyName',PropertyValue,...)
handle = uicontrol(parent,'PropertyName',PropertyValue,...)
handle = uicontrol
uicontrol(uich)
uicontrol creates a uicontrol graphics objects (user interface controls), which you use to implement graphical user interfaces.
handle = uicontrol('PropertyName',PropertyValue,...) creates a uicontrol and assigns the specified properties and values to it. It assigns the default values to any properties you do not specify. The default uicontrol style is a pushbutton. The default parent is the current figure. See the Uicontrol Properties reference page for more information.
handle = uicontrol(parent,'PropertyName',PropertyValue,...) creates a uicontrol in the object specified by the handle, parent. If you also specify a different value for the Parent property, the value of the Parent property takes precedence. parent can be the handle of a figure, uipanel, or uibuttongroup.
handle = uicontrol creates a pushbutton in the current figure. The uicontrol function assigns all properties their default values.
uicontrol(uich) gives focus to the uicontrol specified by the handle, uich.
When selected, most uicontrol objects perform a predefined action. MATLAB software supports numerous styles of uicontrols, each suited for a different purpose:
Check boxes
Editable text fields
Frames
List boxes
Pop-up menus
Push buttons
Radio buttons
Sliders
Static text labels
Toggle buttons
For information on using these uicontrols within GUIDE, the MATLAB GUI development environment, see Examples: Programming GUI Components in the MATLAB Creating GUIs documentation
To create a specific type of uicontrol, set the Style property as one of the following strings:
'checkbox' – Check boxes generate an action when selected. These devices are useful when providing the user with a number of independent choices. To activate a check box, click the mouse button on the object. The state of the device is indicated on the display.
'edit' – Editable text fields enable users to enter or modify text values. Use editable text when you want text as input. If Max-Min>1, then multiple lines are allowed. For multi-line edit boxes, a vertical scrollbar enables scrolling, as do the arrow keys.
'frame' – Frames are rectangles that provide a visual enclosure for regions of a figure window. Frames can make a user interface easier to understand by grouping related controls. Frames have no callback routines associated with them. Only other uicontrols can appear within frames.
Frames are opaque, not transparent, so the order in which you define uicontrols is important in determining whether uicontrols within a frame are covered by the frame or are visible. Stacking order determines the order objects are drawn: objects defined first are drawn first; objects defined later are drawn over existing objects. If you use a frame to enclose objects, you must define the frame before you define the objects.
Note Most frames in existing GUIs can now be replaced with panels (uipanel) or button groups (uibuttongroup). GUIDE continues to support frames in those GUIs that contain them, but the frame component does not appear in the GUIDE Layout Editor component palette. |
'listbox' – List boxes display a list of items and enable users to select one or more items. The Min and Max properties control the selection mode:
If Max-Min>1, then multiple selection is allowed.
If Max-Min<=1, then only single selection is allowed.
The Value property indicates selected entries and contains the indices into the list of strings; a vector value indicates multiple selections. MATLAB evaluates the list box's callback routine after any mouse button up event that changes the Value property. Therefore, you may need to add a "Done" button to delay action caused by multiple clicks on list items.
List boxes whose Enable property is on differentiate between single and double left clicks and set the figure SelectionType property to normal or open accordingly before evaluating the list box's Callback property. For such list boxes, Ctrl-left click and Shift-left click also set the figure SelectionType property to normal or open to indicate a single or double click.
'popupmenu' – Pop-up menus (also known as drop-down menus or combo boxes) open to display a list of choices when pressed. When not open, a pop-up menu indicates the current choice. Pop-up 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 requires.
'pushbutton' – Push buttons generate an action when pressed. To activate a push button, click the mouse button on the push button.
'radiobutton' – Radio buttons are similar to check boxes, but are intended to be mutually exclusive within a group of related radio buttons (i.e., only one is in a pressed state at any given time). To activate a radio button, click the mouse button on the object. The state of the device is indicated on the display. Note that your code can implement mutually exclusive behavior for radio buttons.
'slider' – Sliders accept numeric input within a specific range by enabling the user to move a sliding bar. Users move the bar by pressing the mouse button and dragging the pointer over the bar, or by clicking in the trough or on an arrow. The location of the bar indicates a numeric value, which is selected by releasing the mouse button. You can set the minimum, maximum, and current values of the slider.
'text' – Static text boxes display lines of text. Static text is typically used to label other controls, provide directions to the user, or indicate values associated with a slider. Users cannot change static text interactively and there is no way to invoke the callback routine associated with it.
'togglebutton' – Toggle buttons are controls that execute callbacks when clicked on and indicate their state, either on or off. Toggle buttons are useful for building toolbars.
Adding a uicontrol to a figure removes the figure toolbar when the figure's Toolbar property is set to 'auto' (which is the default). To prevent this from happening, set the Toolbar property to 'figure'. The user can restore the toolbar by selecting Figure Toolbar from the View menu regardless of this property setting.
The uicontrol function accepts property name/property value pairs, structures, and cell arrays as input arguments and optionally returns the handle of the created object. You can also set and query property values after creating the object using the set and get functions.
A uicontrol object is a child of a figure, uipanel, or uibuttongroup and therefore does not require an axes to exist when placed in a figure window, uipanel, or uibuttongroup.
When MATLAB is paused and a uicontrol has focus, pressing a keyboard key does not cause MATLAB to resume. Click anywhere outside a uicontrol and then press any key. See the pause function for more information.
The following statement creates a push button that clears the current axes when pressed.
h = uicontrol('Style', 'pushbutton', 'String', 'Clear',...
'Position', [20 150 100 70], 'Callback', 'cla');This statement gives focus to the pushbutton.
uicontrol(h)
You can create a uicontrol object that changes figure colormaps by specifying a pop-up menu and supplying an M-file name as the object's Callback:
hpop = uicontrol('Style', 'popup',...
'String', 'hsv|hot|cool|gray',...
'Position', [20 320 100 50],...
'Callback', 'setmap');The above call to uicontrol defines four individual choices in the menu: hsv, hot, cool, and gray. You specify these choices with the String property, separating the choices 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. setmap contains these statements:
val = get(hpop,'Value');
if val == 1
colormap(hsv)
elseif val == 2
colormap(hot)
elseif val == 3
colormap(cool)
elseif val == 4
colormap(gray)
endThe Value property contains a number that indicates the selected choice. 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.
textwrap, uibuttongroup, uimenu, uipanel
![]() | Uicontextmenu Properties | Uicontrol Properties | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |