Create Objects with the uicontrol Function
Create control objects using the uicontrol function.
The uicontrol function takes multiple input arguments for creating graphical widgets with different functions, styles, shapes and sizes. By changing the input arguments of uicontrol, you can create different control objects.
The following table provides details of the type of widgets, namely style properties,
that you can create with the uicontrol command by applying the
'style'
argument followed by a style property. For example,
uicontrol('style','pushbutton')
or
uicontrol('style
','edit
')
and
so on.
Style Property | Example | Description |
---|---|---|
pushbutton | Performs a user-defined operation when pressed. | |
togglebutton | Appears like a push button, but serves to visually indicate the state of pressed or not pressed. | |
checkbox | Provides a selection of one or many check boxes within a button group. | |
radiobutton | Provides a group of radio buttons from which you can select one button. | |
edit | Creates a space to enter textual information. | |
text | Displays a predefined text passed as an
argument to uicontrol . |
|
slider | Provides a slider that you drag to select a value between a given range. | |
listbox | Displays a defined list of items from which you can select one or more items. | |
popupmenu | Expands a pop-up menu with a list of options from which you can select. |
uicontrol
object. All valid attributes are described in the
following table:Style Property | Argument | Description |
---|---|---|
units |
pixels normalized |
Units are the measurement units that describe the position and dimensions of a graphical object. 'Pixel' units take values between 0 to 1000 and 'normalized' units take values between 0 and 1. |
position | [0.6 0.16 0.4 0.4] |
Specifies the position and size of the control object in the vector of the form [left top width height]. For example, the values [0.6 0.16 0.4 0.4] in normalized units indicate that 0.6 is the distance from the left where the object starts; 0.16 is the distance from top where the object starts; 0.4 is the width of the object; and 0.4 is the height of the object. |
value |
1 -1 0 (integer or double) |
Specifies the current value of a style property. For example, 1 and 0 for check box or radio buttons if they are selected or not selected, respectively. If the 5th entry of a list box is selected, then the value is '5'. |
enable | on or off | Specifies if a property of the control object is enabled. |
visible | on or off | Specifies the visibility of the control object. |
callback | @callback_function_defined (^this function must take two arguments) |
Defines the function that is to be executed via click or widget action. |
string |
Any text as a string or a cell or
|
Specifies the text that is displayed in the GUI. |
fontangle |
regular italic |
Specifies the angle of the displayed font. Default angle is ‘regular’. |
fontname |
MS Shell Dlg centuar … |
Specifies the name of the displayed font. Default name is ‘MS Shell Dlg’. |
fontsize | Font size number | Specifies the size of the displayed font. Default size is 8. |
fontweight |
normal bold |
Specifies the weight of the displayed font. Default weight is 'normal'. |
You can create and invoke a widget as follows:
- Create a figure handle with assigned positions.
- Add a uipanel to the figure and assign space for a plot.
- Create the required uicontrol objects in the uipanel.
- Assign respective attributes to each control object.
- Define and assign a callback function for each control object.
Review the following code and observe the position and dimensions of the figure object created. Note that position is defined using normalised units.
f = figure('units','normalized','position',[0.2 0.3 0.6 0.7]);
undock(f);
Now, change the position to [0 0 0.4 0.4]
, and run the code again.
The figure shifts its position and dimension according to the new position
arguments.