uicontrol

Creates interactive graphical control objects in a figure. Use the 'style' property of uicontrol to create different types of control objects.

Syntax

h = uicontrol()

h = uicontrol(property, value, ...)

h = uicontrol(parent, property, value, ...)

Inputs

parent
Handle of a container object, which could be a figure, frame, uipanel, or uibuttongroup.
Type: double | integer
property, value
'backgroundcolor'
Specifies the background color. Valid values are 'transparent' or a real vector specifying RGB values in the range 0-255 or 0-1.
Type: string | vector
'callback'
Callback function that is triggered when interacting with h. If value is a function handle, it must be a function that takes two arguments. The first argument is the handle of the uicontrol. The second argument is the event data to the uicontrol. OML passes empty data to the second argument if there is no data to the uicontrol. If value is a string, it must represent a function handle or a function name. If value is a cell, it must contain the function name/function handle in the first cell element and parameters to pass to callback function in the additional elements.
Type: cell | functionhandle | string
'enable'
Specifies if h is enabled. Valid values are 'on'(default) and 'off'.
Type: string
'fontangle'
Specifies the angle of the displayed font. Valid values are 'regular'(default) and 'italic'.
Type: string
'fontname'
Specifies the name of the displayed font.
Type: string
'fontsize'
Specifies the size of the displayed font.
Type: scalar
'fontweight'
Specifies the weight of the displayed font. Valid values are 'normal'(default) and 'bold'.
Type: string
'horizontalalignment'
Specifies the horizontal alignment of the text in styles edit, text and textbox. Valid values are left(default), right, center and justify.
Type: string
'max'
Defines the maximum value of h. By default, it is 1. For the 'listbox' style, set the value to greater than 1 to enable multi-selection.
Type: double | integer
'interruptible'
Specifies if the callback associated with h is interruptible by the user by clicking on the Stop button in the user interface. Valid values are 'off' (default) and 'off'.
Type: string
'min'
Defines the minimum value of h. By default, it is 0. For the 'listbox' style, set the value to greater than 1 to enable multi-selection.
Type: double | integer
'orient'
Specifies the orientation of style slider. Valid values are horizontal (default) and vertical.
Type: string
'parent'
Specifies the parent.
Type: scalar.
'position'
Position and size of h. Value is specified as a vector of the form [left top width height]. If 'units' has a value of 'normalized', values must be between 0 to 1.
Type: vector
'string'
Text to be displayed on h.
Type: string | cell
'style'
Property of uicontrol for creating different types of control objects. Valid values for this property are:
'buttongroup'
Creates a group which can be used to manage related radio buttons.
'checkbox'
Creates a checkbox. By default, if there is a string associated with a checkbox, the string has the focus and a checkbox can be toggled using it.
'edit'
Creates a single line text editor.
'textbox'
Creates a multi-line text editor. A key combination of SHIFT + ENTER will result in a new line in the editor. A key press of just ENTER will trigger the callback function.
'frame'
Creates a frame, which can be used as a parent when creating uicontrol objects to group them.
'listbox'
Creates a list box.
'popupmenu'
Creates a popup menu.
'pushbutton'
Creates a button if no 'style' is specified. A uicontextmenu can be attached to this style, where a context menu is displayed with a right-mouse click.
'radiobutton'
Creates radiobuttons.
'slider'
Creates a slider to select an integral value from a range.
'text'
Creates a label.
'togglebutton'
Creates a toggle button. A uicontextmenu can be attached to this style, where a context menu is displayed with a right-mouse click.
'waitbar'
Creates a progress bar.
'tag'
User-defined string to tag graphical control objects.
Type: string
'tooltipstring'
Tooltip to display.
Type: string
'units'
Specifies units of measurement. Valid values are 'pixels' (default) and 'normalized'.
Value 'pixel' indicates that h has a fixed size and position specified by 'position'.
Value 'normalized' indicates that h will be resized if parent is resized.
Type: string
'userdata'
User-defined numerical data.
Type: complex | mtx | scalar
'value'
Current value of h.
Type: double | integer
'verticalalignment'
Specifies the vertical alignment of the text in styles edit, text and textbox. Valid values are top, bottom and middle (default).
Type: string
'visible'
Specifies if h is visible. Valid values are 'on' (default) and 'off'.
Type: string

Outputs

h
Handle of the uicontrol.

Examples

Create a push button with a callback function:
close all;
figure('units', 'normalized', 'position', [0.25 0.25 0.5 0.5])
axes('units', 'normalized', 'position', [0.2 0.05 0.8 0.8]);
uicontrol('units', 'normalized', 'position', [0.02 0.05 0.16 0.05], 'string', 'plot', 'callback', @plot_rnd);
				
function plot_rnd(handle, callbackdata)
	plot(rand(1, 30));
	disp(handle);
end
Figure 1.
Click the button in the figure:
Figure 2.

Comments

When setting the value of 'style', a short form can be used as long as there is only one match for it. For example, 'pop' can be set for 'popupmenu'.