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.
- 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.
- '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.
- 'enable'
- Specifies if h is enabled. Valid values are 'on'(default) and 'off'.
- 'fontangle'
- Specifies the angle of the displayed font. Valid values are 'regular'(default) and 'italic'.
- 'fontname'
- Specifies the name of the displayed font.
- 'fontsize'
- Specifies the size of the displayed font.
- 'fontweight'
- Specifies the weight of the displayed font. Valid values are 'normal'(default) and 'bold'.
- '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.
- '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.
- 'parent'
- Specifies the parent.
- '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.
- 'string'
- Text to be displayed on h.
- '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. 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.
- 'tooltipstring'
- Tooltip to display.
- 'units'
- Specifies units of measurement. Valid values are 'pixels' (default) and 'normalized'.
- 'userdata'
- User-defined numerical data.
- 'value'
- Current value of h.
- 'visible'
- Specifies if h is visible. Valid values are 'on' (default) and 'off'.
Outputs
- h
- Handle of the uicontrol.
Examples
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
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'.