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
'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
'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
'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
'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.
'edit'
Creates a text editor.
'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.
'radiobutton'
Creates radiobuttons.
'slider'
Creates a slider to select an integral value from a range.
'text'
Creates a label.
'togglebutton'
Creates a toggle button.
'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
'visible'
Specifies if h is visible. Valid values are 'on' (default) and 'off'.
Type: string

Outputs

h
Handle of the uicontrol.

Examples

Creating 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'.