App Designer
App Designer
App Designer
Users Guide
www.mathworks.com
www.mathworks.com/sales_and_services
User community:
www.mathworks.com/matlabcentral
Technical support:
www.mathworks.com/support/contact_us
Phone:
508-647-7000
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
October 2014
Online only
Contents
1-2
1-3
1-3
1-4
1-5
1-6
App Layout
Add and Delete Components . . . . . . . . . . . . . . . . . . . . . . . . . .
2-2
Component Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-3
2-4
Move Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-5
Align Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Manual Component Alignment . . . . . . . . . . . . . . . . . . . . . . .
Automatic Component Alignment . . . . . . . . . . . . . . . . . . . . .
2-6
2-6
2-6
Space Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-7
iii
App Programming
App Designer Code Generation . . . . . . . . . . . . . . . . . . . . . . . .
3-2
3-5
3-6
3-6
3-8
3-10
3-11
App Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3-13
3-16
3-16
3-16
3-18
3-18
3-18
App Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
App Displaying Single Plot in an Axes . . . . . . . . . . . . . . . .
App Displaying Multiple Axes . . . . . . . . . . . . . . . . . . . . . . .
App Displaying Two Plots in One Axes . . . . . . . . . . . . . . . .
App Displaying Slider Value as it Changes . . . . . . . . . . . . .
App to Change Lamp Color Based on Button Group Selection
App That Resizes Component When Window Resizes . . . . .
3-19
3-19
3-22
3-25
3-27
3-29
3-30
Keyboard Shortcuts
Component Selection Shortcuts . . . . . . . . . . . . . . . . . . . . . . .
iv
Contents
4-2
4-3
4-4
4-5
4-6
4-7
4-8
Property Reference
Function Reference
vi
1
App Designer Basics
Open App Designer on page 1-2
App Creation and Modification on page 1-3
Uninstall App Designer Tech Preview on page 1-6
To open a previously created app with App Designer, type the following, where filename
the name of an app file (.mlapp) on the MATLAB search path:
appdesigner filename
1-2
From the App Designer component palette on the left, drag a Slider and a Numeric
Edit Field into the central design area.
1-3
In the central design area, right-click the slider and select Callbacks > Edit
ValueChangedFcn.
In the Edit ValueChangedFcn Callback dialog box, accept the default name by
clicking OK.
Although not done here (to keep the example simple), changing the function name
makes it easier to associate the callback code with a component, particularly when
there are multiple instances of the same component in an app.
In the code file that opens, add the following code under function
SliderValueChanged(app). The code directs MATLAB to update the numeric edit
field to reflect the slider bar location.
app.NumericEditField.Value = app.Slider.Value;
Your code can access all components and their values directly, similar to the way
that you access fields of a structure array. To access or set a property value, specify
the app that you are designing (which is always app), the component, and the
component property name.
6
Test the app by changing the slider value and releasing the mouse button. The numeric
edit field reflects the new value.
App Displaying Slider Value as it Changes on page 3-27, updates the edit field
continuously as the slider is moved.
1-4
In the Open dialog box, navigate to the folder containing your MLAPP file and
specify the name in the File name field.
Click Open.
Alternatively, you can type the file name (excluding the .mlapp file extension) in the
MATLAB Command Window. The file must be in a folder on your MATLAB path.
In the Open dialog box, navigate to the folder containing your MLAPP file and
specify the name in the File name field.
Click Open.
App Designer displays the app in design view.
Alternatively, in MATLAB Command Window, type this command, where filespec is the
file name, full file path, or partial file path of the app file (.mlapp):
appdesigner filespec
If you type just the file name, the file must be in a folder on your MATLAB path.
1-5
1-6
2
App Layout
Add and Delete Components on page 2-2
Component Selection on page 2-3
Resize App Window on page 2-4
Move Components on page 2-5
Align Components on page 2-6
Space Components on page 2-7
App Layout
2-2
Component Selection
Component Selection
Component selection is the first step in performing many operations.
Selection
How To
Single component
Multiple components
Press Ctrl+A.
2-3
App Layout
2-4
Move Components
Move Components
You can move components manually (freehand) or by set increments, as follows:
Freehand Drag the component or components.
1-pixel increments Select the component or components. Press a keyboard Arrow
key in the direction that you want to move the component.
10-pixel increments Select the component or components. Press Shift+Arrow in
the direction that you want to move the component.
To cancel an in-process freehand move operation, press the Escape key.
2-5
App Layout
Align Components
You can direct App Designer to align components automatically, or you can align them
manually. For instance, you can use the manual method for an initial layout, and then
polish the layout using automatic alignment.
2-6
On the Layout tab, in the Alignment section, click a control to indicate how you
want those components to align.
Space Components
Space Components
You can direct App Designer to space components automatically, or you can manually
specify spacing, as follows:
1
In the design area, select the components that you want to space.
You must select two or more components to space manually and three or more
components to space automatically.
Select how you want spacing applied by selecting Apply horizontally or Apply
vertically.
2-7
2-8
3
App Programming
App Designer Code Generation on page 3-2
Component Name in App Code on page 3-5
Callbacks Programmed Response to User Actions on page 3-6
Debug App Code on page 3-10
Share Data Across Callbacks on page 3-11
App Functions on page 3-13
Rename Components, Properties, Callbacks, and Functions on page 3-16
Delete Components, Properties, Callbacks, and Functions on page 3-18
App Examples on page 3-19
App Programming
3-2
3-3
App Programming
Notice that:
The first section of code defines the app properties.
Initially, this section contains the properties that correspond to the app and the app
components. If you add properties to share data, App Designer adds your properties to
this region. For information on adding properties, see Share Data Across Callbacks
on page 3-11
The second section of code contains the app functions.
Initially, this section contains the framework for the startup function. If you add
callbacks or other functions to the app, App Designer adds them to this region. For
information on adding functions, see Callbacks Programmed Response to User
Actions on page 3-6 and App Functions on page 3-13.
The third section of code initializes and creates the app and its components.
If you select a component in design view and use the Properties tab to change
property values for that component, App Designer reflects those changes in this
section of the code.
If you rename a component,property, or function (including a callback function), App
Designer updates the name in the read-only and read-write areas of the code.
3-4
3-5
App Programming
Callback Creation
You can create a component callback from design view or code view:
To create a callback from design view, right-click the component and select Callbacks
> Edit callback-name.
To create a callback from code view, in the code browser, right-click the component
and select Callbacks > Edit callback-name.
3-6
In the Add Callback Function dialog box, enter a name for your callback and click
OK.
App Designer displays code view.
A best practice is to name the callback so that you can easily identify the control
with which it is associated in the app code and what the callback does. For instance,
if you intend for a button push to result in data being plotted, you might name the
button callback PlotButtonPushed.
At the location in the code where App Designer places the cursor, type the code that
you want MATLAB to run when the user manipulates the control.
Refer to components and their properties using app. as a prefix for each component.
This makes it possible to access properties directly, similar to the way you access
fields of a structure. For example, to set the Enabled property of the slider named
TempSlider to 'off', use the following code:
app.TempSlider.Enabled = 'off';
Tip To view component property names and a brief description of each, click the info
icon next to a component in the code browser.
3-7
App Programming
Note: Multiple components cannot share a callback. If you want to share code among
callbacks, consider writing a function and calling it from multiple callbacks, as described
in App Functions on page 3-13.
For detailed callback examples, see App Examples on page 3-19.
App Initialization
Use the app startup function to perform tasks that you want MATLAB to perform when
the app first opens. MATLAB runs the startup function after creating the components.
For instance, use the startup function if you want an axes to appear with a default plot
when the app opens or if you want to initialize app properties.
To access the startup function in your app, from code view, click View Startup
Function on the Editor tab.
Display Plot in Axes When the App Opens
This example shows how to create an app that opens with a plot in an axes.
3-8
In App Designer:
1
3-9
App Programming
3-10
Drag a Button and a Numeric Edit Field into the design area.
App Programming
In the code browser, right-click app.Button and select Callbacks > Edit
ButtonPushedFcn.
In the Add Callback Function dialog box, click OK . (Accept the default callback
function name.)
Add code to increment the counter and display the counter value in the numeric edit
field each time the user clicks the push button.
Immediately after the function ButtonButtonPushed(app) line, add:
app.Counter = app.Counter + 1;
app.NumericEditField.Value = app.Counter;
3-12
App Functions
App Functions
In addition to coding callback functions for your app, you can create app functions
that are independent of any particular component. For example, you can create an
app function to perform a calculation. You can then call that function from multiple
callback functions, eliminating the need to repeat that code in each callback that uses the
calculation.
App to Perform a Calculation
This example shows how to create an app that performs a calculation. It uses a function,
mycalc, to calculate the sum and product of two values specified by the user. When the
user changes either value, the app recalculates the sum and product by calling mycalc.
In App Designer:
1
Add four numeric edit fields and labels to the design area, as shown in the preceding
image and described in this table.
Component
Associated Label
Text
Value 1:
Value1
None
3-13
App Programming
Component
Associated Label
Text
Value 2:
Value2
None
Sum:
Sum
Minimum:-Inf
Maximum: Inf
Editable: Clear this check
box.
Product:
Product
Minimum:-Inf
Maximum: Inf
Editable: Clear this check
box.
Create the function to calculate the sum and the product of the values that the user
enters for value 1 and value 2:
a
Add code to get the user-entered values, perform calculations, and assign a
vector to the function output argument, result.
Immediately after the function result = mycalc(app) line, add:
a = app.Value1.Value;
b = app.Value2.Value;
sum = a+b;
prod = a*b;
result = [sum,prod];
3-14
Code the callback for the Value 1 numeric edit field to call the mycalc function
whenever the user changes the field value:
a
In the code browser, right-click app.Value1 and select Callbacks > Edit
ValueChangedFcn.
In the Add Callback Function dialog box, change the name to Value1Changed,
and then click OK.
App Functions
Code the callback for the Value 2 numeric edit field to call the mycalc function
whenever the user changes the field value:
a
In the code browser, right-click app.Value2 and select Callbacks > Edit
ValueChangedFcn.
In the Add Callback Function dialog box, change the name to Value2Changed,
and then click OK.
3-15
App Programming
Tip If you are unsure which name corresponds to a particular component, use the
thumbnail view of the app that appears below the code browser. Click the component
that you want to identify. App Designer highlights the name of that component in the
code browser.
3-16
In the design area, select the component for which you want to change the code
name.
The Name in Code field displays the name by which that component is referenced
in the code.
3
3-17
App Programming
3-18
App Examples
App Examples
In this section...
App Displaying Single Plot in an Axes on page 3-19
App Displaying Multiple Axes on page 3-22
App Displaying Two Plots in One Axes on page 3-25
App Displaying Slider Value as it Changes on page 3-27
App to Change Lamp Color Based on Button Group Selection on page 3-29
App That Resizes Component When Window Resizes on page 3-30
3-19
App Programming
3-20
In App Designer, drag an axes and a drop down into the central design area. Arrange
them as shown in the preceding image.
In the design area, select the drop down, and then, on the Properties tab, click
Options.
Set the properties for the drop down as shown in the image that follows.
App Examples
To delete a row, select it, and then click the minus button.
The user will see the text values in the drop down. The text data values are numeric
values associated with each option. You might find it easier to code callbacks using
functions that operate on numeric values rather than string values.
4
Close the Options dialog box, and then click Code View.
Specify the plot that you want to appear in the app when it first opens by adding
code to the startup function.
On the Editor tab, click View Startup Function. Add this code to the startup
function:
app.Data = [75 91 105 123.5 131 150 179 203 226 249 281.5];
bar(app.Axes, app.Data);
3-21
App Programming
In the Add Callback Function dialog box, click OK. (Accept the default callback
function name.)
3-22
App Examples
In the App Designer, drag the components described in the following table into the
central design area. Arrange the components as shown in the preceding image.
Component
Name in Code
Nondefault Property
Settings
Axes
AxesFreq
Not Applicable
Frequency
Axes
AxesTime
Not Applicable
Time
f1
f2
Edit Field
EditFieldTime
Not Applicable
3-23
App Programming
2
3
Component
Name in Code
Nondefault Property
Settings
Button
Button
Text: Plot
Not Applicable
Right-click the Plot button and select Callbacks > Edit ButtonPushedFcn.
In the Add Callback Function dialog box, click OK . (Accept the default callback
function name.)
App Designer opens code view.
Get the input values, perform calculations, and plot the data in the appropriate axes.
Beginning on the line following function ButtonButtonPushed(app) add:
% Get user input
f1 = app.NumericEditFieldf1.Value;
f2 = app.NumericEditFieldf2.Value;
t = eval(app.EditFieldTime.Value);
%
x
y
m
f
Calculate data
= sin(2*pi*f1*t) + sin(2*pi*f2*t);
= fft(x,512);
= y.*conj(y)/512;
= 1000*(0:256)/512;
Test the app by trying the various app controls in the running app. Notice that:
The numeric edit fields, f1 and f2, display an error message if you enter a
nonnumeric value or one that exceeds the maximum that you set.
3-24
App Examples
The edit field for the time vector does not prevent you from entering an invalid vector.
To handle invalid time vector values, define a ValueChangedFcn callback function for
the EditFieldTime component, and then code it to determine if the users entries
are valid.
App Programming
In App Designer, drag an axes and two buttons into the central design area. Arrange
them as shown in the preceding image and as described in this table.
Component
Text
Name in Code
Button
Plot 1 (line x)
Plot1
Button
Plot 2 (line o)
Plot2
In the Add Callback Function dialog box, click OK . (Accept the default callback
function name.)
The last input argument to the plot function specifies that the plot will be
represented with a series of x characters.
The hold statement ensures that additional plots will not overwrite any existing
plots in the specified axes.
8
3-26
App Examples
In the code browser, right-click app.Plot2 and select Callbacks > Edit
ButtonPushedFcn.
9
In the Add Callback Function dialog box, click OK . (Accept the default callback
function name.)
3-27
App Programming
In App Designer, drag a Slider and a Numeric Edit Field into the central design
area, arranging them as shown in the preceding image.
In the Add Callback Function dialog box, click OK. (Accept the default callback
function name.)
App Examples
As you do so, the numeric edit field is continuously updated to display the current
slider value.
Click the slider.
The numeric edit field is updated to display the new slider value.
In App Designer, drag a Radio Button Group, a Lamp, and a Label into the
central design area. Arrange them as shown in the preceding image and described in
this table.
Component
Title or Text
Name in Code
ButtonGroup
Indicator
ButtonGroup (default)
RadioButton
Stop
StopRadioButton
RadioButton
Caution
CautionRadioButton
3-29
App Programming
Component
Title or Text
Name in Code
RadioButton
Go
GoRadioButton
Lamp
Not applicable
Lamp (default)
Label
Status
Label (default)
In the code browser, right click app.ButtonGroup, and then select Callbacks >
SelectionChangeFcn.
In the Add Callback Function dialog box, click OK . (Accept the default callback
function name.)
Add code to determine which radio button is selected and set the lamp color
accordingly.
In the code, beginning on the line after function
ButtonGroupSelectionChange(app, event), add:
switch app.ButtonGroup.SelectedObject
case app.GoRadioButton
app.Lamp.Color = 'green';
case app.CautionRadioButton
app.Lamp.Color = 'yellow';
case app.StopRadioButton
app.Lamp.Color = 'red';
end
App Examples
In App Designer, drag a Slider into the middle of the central design area.
In the code browser, right-click app.AppWindow, and then select Callbacks >
Edit SizeChangedFcn.
In the Add Callback Function dialog box, click OK. (Accept the default callback
function name.)
At the cursor location in code view, beginning with the line after function
AppWindowSizeChange(app) add this code.
windowpos = app.AppWindow.Position;
slidersize = app.Slider.Size;
% Subtract the slider height from the
% window height and divide by 2.
app.Slider.Location = [30, (windowpos(4)-6)/2];
% Subtract 60 from the window width.
app.Slider.Size = [windowpos(3)-60, slidersize(2)];
The code gets the app window width and height after a resize operation. The code
updates the location and size of the slider to keep it centered in the app window, 30
pixels from the left and right sides of the window.
3-31
App Programming
3-32
4
Keyboard Shortcuts
Component Selection Shortcuts on page 4-2
Component Move Shortcuts on page 4-3
Component Resize Shortcuts on page 4-4
Component Copy, Paste, Duplicate, and Delete Shortcuts on page 4-5
Component Alignment Shortcuts on page 4-6
Redo, Undo, and Cancel Operation Shortcuts on page 4-7
Run, Save, and Open App Shortcuts on page 4-8
Keyboard Shortcuts
Key or Keys
Tab
4-2
Key or Keys
Down Arrow
Left Arrow
Right Arrow
Up Arrow
Shift+Down Arrow
Shift+Left Arrow
Shift+Right Arrow
Shift+Up Arrow
Escape
4-3
Keyboard Shortcuts
Key
Resize component while maintaining aspect Press and hold down the Shift key before
ratio.
you begin to drag the component expander.
Cancel an in-progress resize operation.
4-4
Escape
Key or Keys
Ctrl+X
Backspace or Delete
4-5
Keyboard Shortcuts
Keys
Ctrl+1
Ctrl+2
Ctrl+3
Ctrl+4
4-6
Ctrl+6
Key or Keys
Ctrl+Y or Ctrl+Shift+Z
Ctrl+Y
Ctrl+Z
Escape
4-7
Keyboard Shortcuts
4-8
Action
Key or Keys
Ctrl+S
F5
Ctrl+O
5
Property Reference
App Window Properties
Axes Properties
Button Properties
Button Group Properties
Check Box Properties
Discrete Knob Properties
Drop Down Properties
Edit Field Properties
Editable Drop Down Properties
Gauge Properties
Knob Properties
Label Properties
Lamp Properties
Linear Gauge Properties
List Box Properties
Ninety Degree Gauge Properties
Numeric Edit Field Properties
Panel Properties
Radio Button Properties
Rocker Switch Properties
Semicircular Gauge Properties
Slider Properties
State Button Properties
Switch Properties
Text Area Properties
Toggle Button Properties
Toggle Switch Properties
Property Reference
Property Reference
5-4
Axes Properties
Axes Properties
Control axes appearance and behavior
Axes properties control the appearance and behavior of an axes object. By changing
property values, you can modify certain aspects of the axes. Use dot notation to refer to a
particular object and property:
window = appwindow;
ax = axes('Parent',window);
color = ax.Color;
ax.Color = 'blue';
Property Reference
Axes Properties
For information on changing the colormap, see the colormap function. For information
on color mapping, see the caxis function.
Setting this property sets the CLimMode property to 'manual'.
CLimMode Selection mode for CLim
'auto' (default) | 'manual'
Selection mode for the CLim property, specified as one of these values:
'auto' Set the CLim property to span the CData limits of the graphics objects
displayed in the axes.
'manual' Use the manually specified CLim values. To specify the values, set the
CLim property. The axes does not change the value of the CLim property when the
limits of axes children change.
Color Color of axes back planes
[1 1 1] (default) | RGB triplet | color string | 'none'
Color of axes back planes, specified as an RGB triplet, a color string, or 'none'. If
you set the color to 'none', then the axes is invisible and the app window color shows
through.
An RGB triplet is a three-element row vector whose elements specify the intensities of
the red, green, and blue components of the color. The intensities must be in the range
[0,1], for example, [0.4 0.6 0.7]. This table lists RGB triplet values that have
equivalent color strings.
Long Name
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
Example: [0 0 1]
5-7
Property Reference
Example: 'b'
Example: 'blue'
ColorOrder Colors for multiline plots
seven predefined colors (default) | three-column matrix of RGB triplets
Colors for multiline plots, specified as a three-column matrix of RGB triplets, where each
row defines one color in the color order. The functions that create line plots cycle through
the colors defined by the ColorOrder property to color each line plotted.
The default color order has seven colors.
Default Color Order
0.4470
0.3250
0.6940
0.1840
0.6740
0.7450
0.0780
0.7410
0.0980
0.1250
0.5560
0.1880
0.9330
0.1840]
The functions that create line plots cycle through the colors to color each line. The hold
state for the axes affects the colors used:
If the hold state for the axes is off (when the NextPlot property is set to 'replace',
then high-level plotting functions such as plot reset the color order to the default
colors before plotting. If you want to specify new colors for the color order and
do not want high-level plotting functions to reset them, then set the NextPlot
property to 'replacechildren'. Alternatively, you can specify a new default
value for the ColorOrder property on the root using the set function. For example,
set(groot,'defaultAxesColorOrder',[0 1 0; 0 0 1]).
If the hold state from the axes is on (when the NextPlot property is set to 'add'),
then plotting functions cycle through the colors starting from the place in the color
order where the last plot ended.
Data Types: single | double
CreateFcn Creation callback
'' (default) | function handle | cell array | string
Creation callback, specified as one of these values:
5-8
Axes Properties
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB command or function, which is evaluated in the base
workspace (not recommended)
Use this property to execute code when the axes is created. Setting the CreateFcn
property on an existing axes has no effect. You must define a default value for this
property, or define this property using a Name,Value pair during axes creation.
MATLAB executes the callback after creating the axes and setting all of its properties.
If you specify this callback using a function handle, MATLAB passes two arguments to
the callback function when executing the callback:
The axes object You can access properties of the axes object from within the
callback function. You also can access the axes object through the CallbackObject
property of the root, which can be queried using the gcbo function.
Event data This argument is empty for this property. Replace it with the tilde
character (~) in the function definition to indicate that this argument is not used.
For more information on how to use function handles to define callback functions, see the
Callback Definition topic in the MATLAB documentation.
Example: @myCallback
Example: {@myCallback,arg3}
DataAspectRatio Relative length of data units along each axis
[1 1 1] (default) | three-element vector of the form [dx dy n]
Relative length of data units along each axis, specified as a three-element vector of
the form [dx dy n]. The first two vector elements define the relative x and y data
scale factors. The third vector element is ignored, but must be included. For example,
specifying this property as [1 2 1] sets the length of one unit of data in the x-direction
to be the same length as two units of data in the y-direction.
The DataAspectRatio property interacts with the PlotBoxAspectRatio, XLimMode,
and YLimMode properties to control how MATLAB scales the x-axis and y-axis.
Setting a value for the DataAspectRatio disables the stretch-to-fill the app window
shape behavior if DataAspectRatioMode and PlotBoxAspectRatioMode are both set to
'auto'.
5-9
Property Reference
If the associated mode property is set to 'auto', then MATLAB chooses the ratio values.
If you set this property, then MATLAB sets the mode to 'manual'.
Example: [1 1 1]
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 |
uint32 | uint64
DataAspectRatioMode Selection mode for DataAspectRatio
'auto' (default) | 'manual'
Selection mode for DataAspectRatio specified as one of these values:
'auto' Use values that make best use of the area provided by the app window.
'manual' Use the manually specified values. To specify the values, set the
DataAspectRatioMode to 'manual'. Changing DataAspectRatioMode to 'manual'
disables the stretch-to-fill the app window shape behavior if DataAspectRatioMode
and PlotBoxAspectRatioMode property values are both set to 'auto'.
This table describes the interactions among properties when you disable the stretchto-fill behavior.
XLimitMode, and
YLimitMode
DataAspectRatioMode
PlotBoxAspectRatioMode Behavior
'auto'
'auto'
'auto'
'auto'
'auto'
'manual'
Limits chosen to
span data range
in all dimensions.
MATLAB modifies
DataAspectRatio to
achieve the requested
PlotBoxAspectRatio
within the limits the
software selected.
'auto'
'manual'
'auto'
Limits chosen to
span data range
in all dimensions.
MATLAB modifies
5-10
Axes Properties
XLimitMode, and
YLimitMode
DataAspectRatioMode
PlotBoxAspectRatioMode Behavior
'auto'
'manual'
'manual'
Limits chosen to
completely fit and
center the plot
within the requested
PlotBoxAspectRatio
given the requested
DataAspectRatio (this
might produce empty
space around 2 of the 3
dimensions).
'manual'
'auto'
'auto'
MATLAB honors
limits and modifies the
DataAspectRatio and
PlotBoxAspectRatio as
necessary.
'manual'
'auto'
'manual
MATLAB honors
limits and
PlotBoxAspectRatio
and modifies
DataAspectRatio as
necessary.
'manual'
'manual'
'auto'
PlotBoxAspectRatio to
achieve the requested
DataAspectRatio
within the limits the
software selected.
Property Reference
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB command or function, which is evaluated in the base
workspace (not recommended)
Use this property to execute code when the axes is deleted. MATLAB executes the
callback before destroying the axes so that the callback can access its property values.
If you specify this callback using a function handle, MATLAB passes two arguments to
the callback function when executing the callback:
The axes object You can access properties of the axes object from within the
callback function. You also can access the axes object through the CallbackObject
property of the root, which can be queried using the gcbo function.
Event data This argument is empty for this property. Replace it with the tilde
character (~) in the function definition to indicate that this argument is not used.
For more information on how to use function handles to define callback functions, see the
Callback Definition topic in the MATLAB documentation.
Example: @myCallback
Example: {@myCallback,arg3}
FontAngle Character slant
'normal' (default) | 'italic'
Character slant, specified as 'normal' or 'italic'. Setting this property to italic
selects a slanted version of the font, if it is available on the app users system. Not all
fonts have both font styles, therefore, the italic font might look the same as the normal
font.
FontSize Font size
10 (default) | scalar numeric value
Font size, specified as a scalar numeric value. The FontSize property determines the size
of the text used for the axis labels and the title. The FontUnits property determines the
units used to interpret the font size.
Example: 12
5-12
Axes Properties
Description
'points'
'inches'
Inches
'centimeters'
Centimeters
'characters'
'normalized'
'pixels'
If you set the FontSize and the FontUnits in one function call, you must set the
FontUnits property first so that the axes correctly interprets the specified FontSize.
FontWeight Thickness of text characters
'normal' (default) | 'bold'
Thickness of the text characters, specified as one of these values:
'normal' Default weight as defined by the particular font
'bold' Thicker character outlines than 'normal'
Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result
in the normal font weight.
GridColor Color of grid lines
[0.15 0.15 0.15] (default) | RGB triplet | color string | 'none'
5-13
Property Reference
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
To set the colors for the axes box outline, use the XColor and YColor properties.
Example: [0 0 1]
Example: 'b'
Example: 'blue'
GridColorMode Selection mode for GridColor
'auto' (default) | 'manual'
Selection mode for the GridColor property, specified as 'auto' or 'manual'. The color is
based on the values of the GridColorMode, XColorMode, and YColorMode properties.
These table lists the grid line colors for different combinations of color modes.
5-14
GridColorMode Property
XColorMode Property
'auto'
'auto'
Determined by GridColor
property
'auto'
'manual'
Determine by
XGridColorproperty
Axes Properties
GridColorMode Property
XColorMode Property
'manual'
'auto'
Determined by GridColor
property
'manual'
'manual'
Determined by GridColor
property
GridColorMode Property
YColorMode Property
'auto'
'auto'
Determined by GridColor
property
'auto'
'manual'
Determine by
YGridColorproperty
'manual'
'auto'
Determined by GridColor
property
'manual'
'manual'
Determined by GridColor
property
Line Style
'-'(default)
Solid line
'+'
'o'
Circle markers
'*'
Star markers
'.'
Point markers
'x'
Cross markers
's'
Square markers
'd'
Diamond markers
'^'
'v'
'>'
Property Reference
Specifier
Line Style
'<'
'p'
'h'
Combine strings to specify lines with markers, such as '-*'. The plot cycles through the
line styles only after using all the colors contained in the ColorOrder property. If the hold
state for the axes is off (when the NextPlot property of the axes is set to 'replace'),
then high-level plotting functions such as plot reset the line style order to the default
line styles before plotting.
If you want to specify a set of line styles that is different from the default and do not
want high-level plotting functions to reset the LineStyleOrder property, then set
NextPlot to 'replacechildren'. Alternatively, you can specify a new default value
for the LineStyleOrder property on the root using the set function. For example,
set(groot,'defaultAxesLineStyleOrder',{'-*',':','o'}).
Example: {'-*',':','o'}
LineWidth Width of axes outline, tick marks, and grid lines
0.5 (default) | scalar value
Width of axes outline, tick marks, and grid lines, specified as a scalar value in point
units. One point equals 1/72 inch. The default value is 0.5 point.
Example: 1.5
MinorGridColor Color of minor grid lines
[0.1 0.1 0.1] (default) | RGB triplet | color string
Color of minor grid lines, specified as an RGB triplet, a color string, or 'none'.
An RGB triplet is a three-element row vector whose elements specify the intensities of
the red, green, and blue components of the color. The intensities must be in the range
[0,1], for example, [0.4 0.6 0.7]. This table lists RGB triplet values that have
equivalent color strings.
5-16
Long Name
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
Axes Properties
Long Name
Short Name
RGB Triplet
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
Example: [0 0 1]
Example: 'b'
Example: 'blue'
NextPlot Properties to reset when adding new plot
'replace' (default) | 'add' | 'replacechildren'
Properties to reset when adding a new plot to the axes, specified as one of these values:
'replace' Reset all axes properties, except Position and Units, to their default
values and delete all axes children before displaying the new plot. Using this value is
similar to using cla reset.
'add' Use the existing axes to add more plots to the axes and do not reset
properties.
'replacechildren' Remove all child objects before adding new plots, but do not
reset axes properties. This is similar to using cla.
The newplot function simplifies the use of the NextPlot property and is useful for
writing custom graphing functions.
OuterPosition Size and location of axes including labels, title, and margins
[0 0 1 1] (default) | [left bottom width height]
Size and location of axes including labels, title, and margins, specified as a four-element
vector of the form [left bottom width height]. This vector defines the extents of
the rectangle that encloses the outer bounds of the axes. The left and bottom elements
define the distance from the lower-left corner of the app window that contains the axes
to the lower-left corner of the rectangle. The last two elements, width and height
elements are the rectangle dimensions.
5-17
Property Reference
The values are measured in units normalized to the container. The default value of [0 0
1 1] includes the whole interior of the container.
In the following image, the red rectangle encloses the region defined by the OuterPosition
property. The green rectangle encloses the region defined by the Position property.
For more information, see the Axes Resize to Accommodate Titles and Labels topic in
the MATLAB documentation.
Parent Parent of axes
app window object
5-18
Axes Properties
DataAspectRatioMode
PlotBoxAspectRatioMode Behavior
'auto'
'auto'
'auto'
Property Reference
XLimitMode, and
YLimitMode
DataAspectRatioMode
PlotBoxAspectRatioMode Behavior
'auto'
'auto'
'manual'
Limits chosen to
span data range
in all dimensions.
MATLAB modifies
DataAspectRatio to
achieve the requested
PlotBoxAspectRatio
within the limits the
software selected.
'auto'
'manual'
'auto'
Limits chosen to
span data range
in all dimensions.
MATLAB modifies
PlotBoxAspectRatio to
achieve the requested
DataAspectRatio
within the limits the
software selected.
'auto'
'manual'
'manual'
Limits chosen to
completely fit and
center the plot
within the requested
PlotBoxAspectRatio
given the requested
DataAspectRatio (this
might produce empty
space around 2 of the 3
dimensions).
'manual'
'auto'
'auto'
MATLAB honors
limits and modifies the
DataAspectRatio and
PlotBoxAspectRatio as
necessary.
5-20
Axes Properties
XLimitMode, and
YLimitMode
DataAspectRatioMode
PlotBoxAspectRatioMode Behavior
'manual'
'auto'
'manual
MATLAB honors
limits and
PlotBoxAspectRatio
and modifies
DataAspectRatio as
necessary.
'manual'
'manual'
'auto'
Property Reference
Selection mode for the TickDir property, specified as one of these values:
'auto' Use default tick direction
'manual' Use manually specified tick mark direction. To specify the tick mark
direction, set the TickDir property.
TickLength Tick mark length
[0.01 0.025] (default) | [length,n]
Tick mark length, specified as a two-element vector of the form [length, n]. The first
element is the tick mark length. The second element is ignored (but must be specified).
Specify the values in units normalized relative to the longest of the visible x-axis or y-axis
lines.
Example: [0.02 0.035]
Title Text object used for axes title
text object (default)
Text object used for axes title. Use this text object to change properties of the title text.
window = appwindow;
ax = axes('Parent',window);
ax.Title.String = 'My Graph Title';
ax.Title.FontWeight = 'normal';
Note: To access the axes title text object, use the Title property or the title function.
This text object is not contained in the axes Children property, it cannot be returned by
findobj, and it does not use default values defined for text objects.
Type Type of graphics object
'axes' (default)
Type of graphics object returned as the string 'axes'.
Data Types: char
Units Position units
'normalized' (default) | 'inches' | 'centimeters' | 'pixels' | 'points' |
'characters'
5-22
Axes Properties
Position units, specified as one of the values in the table that follows.
Units
Description
'normalized' (default)
'inches'
Inches.
'centimeters'
Centimeters.
'characters'
'points'
'pixels'
When specifying the units as a Name,Value pair during object creation, you must set the
Units property before specifying the properties that you want to use these units, such as
Position.
Visible Visibility of axes
'on' (default) | 'off'
Visibility of axes, specified as one of these values:
'on' Display the axes.
'off' Hide the axes without deleting it. You still can access the properties of a
invisible axes object.
XAxisLocation Location of x-axis
'bottom' (default) | 'top'
Location of the x-axis, specified as one of these values:
'bottom' Display x-axis at bottom of axes
5-23
Property Reference
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
Example: [1 1 0]
Example: 'y'
Example: 'yellow'
XColorMode, YColorMode Selection mode for axes outline color
'auto' (default) | 'manual'
Selection mode for the axis outline color, specified as one of these values:
'auto' Use the default color.
'manual' Use the manually specified color. To specify the color, set the XColor or
YColor property.
5-24
Axes Properties
See GridColorMode for related information about grid line color selection.
XDir, YDir Direction of increasing values along axis
'normal' (default) | 'reverse'
Direction of increasing values along axis, specified as one of these values:
'normal' Normal direction of increasing values:
x-axis values increase from left to right.
y-axis values increase from bottom to top.
'reverse' Reverse direction of increasing values:
x-axis values decrease from left to right.
y-axis values decrease from bottom to top.
XGrid, YGrid Display of grid lines
'off' (default) | 'on'
Display of grid lines, specified as one of these values:
'off' Do not display the grid lines.
'on' Displays grid lines perpendicular to the axis, for example, along lines of
constant x or y values. Use the grid command to set both properties 'on' or 'off'.
XLabel, YLabel Text object
text object (default)
Text object for x-axis or y-axis, label. Use this text object to change the properties of the
axis label text.
window = appwindow;
ax = axes('Parent',window);
ax.YLabel.String = 'Y Axis';
ax.YLabel.FontSize = 12;
Note: To access the axis label text objects, use XLabel and YLabel, properties or
the xlabel and ylabel functions. These text objects are not contained in the axes
Children property, they cannot be returned by findobj, and they do not use default
values defined for text objects.
5-25
Property Reference
Axes Properties
Property Reference
See Also
More About
5-28
Button Properties
Button Properties
Control push button appearance and behavior
Buttons are app components that typically generate an action when an app user presses
and releases them. Button properties control the appearance and behavior of a particular
instance of a button. To modify aspects of a button, change property values. Use dot
notation to refer to a particular object and property:
button = uibutton;
txt = button.Text;
button.Text = 'Plot';
ButtonPushedFcn Code to execute after app user clicks and releases button
[] (default) | function handle | cell array | string
Code to execute when the app user clicks and releases the button, specified as a function
handle, a cell array containing function handle and additional arguments, or a string.
MATLAB does not execute the callback function if the app user clicks the button, but
then moves the mouse and releases the mouse button while the cursor is outside the
bounds of the button.
Example: @function
Example: {@function, x}
Enabled Operational state of Button
true (default) | false
Operational state of button, specified as true or false.
If you set this property to true, the app user can press the button.
If you set this property to false, the button appears dimmed, indicating that an app
user cannot press it and the button will not trigger a callback.
FontAngle Character slant of button text
'normal' (default) | 'italic'
5-29
Property Reference
Character slant of the button text, specified as 'normal' or 'italic'. Setting this
property to italic selects a slanted version of the font, if it is available on the app users
system.
FontName Font in which to display button text
'Helvetica' (default) | string
Font in which to display the button text, specified as a string. If the specified font is
not available to the app user, MATLAB uses 'Helvetica'. If 'Helvetica' is not
available, MATLAB uses an available sans serif font.
Example: 'Arial'
FontSize Font size of button text
12 (default) | positive number
Font size of button text, specified as a positive number. The units are points.
Example: 14
Data Types: double
FontWeight Thickness of text characters
'normal' (default) | 'bold'
Thickness of the text characters, specified as one of these values:
'normal' Default weight as defined by the particular font
'bold' Thicker character outlines than 'normal'
Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result
in the normal font weight.
HorizontalAlignment Horizontal alignment of icon and text within button
'center' (default) | 'left' | 'right'
Horizontal alignment of text and icon within the button, specified as 'center', 'left',
or 'right'.
The following image shows the three horizontal alignment options, center, left, and right,
when the VerticalAlignment and IconAlignment properties are set to their default values
('center' and 'left', respectively).
5-30
Button Properties
Result
'left'
'center'
'top'
'bottom'
'right'
5-31
Property Reference
Note: The preceding images reflect the icon location when HorizontalAlignment and
VerticalAlignment are each set to their default value, 'center'.
If you specify an empty string ('') for the Text property, then the icon aligns as though
it is text, according to the values set for HorizontalAlignment and VerticalAlignment.
The IconAlignment property value has no effect in this case.
Location Location of button relative to parent
[100,100] (default) | [x,y]
Location of button relative to parent, specified as [x,y], where x and y specify the
coordinates from the lower-left corner of the parent container to the lower-left corner of
the button. The units of measurement are pixels.
OuterLocation Location of button relative to parent container
[100,100] (default) | [x,y]
Identical to Location for buttons.
OuterSize Size of button, including Text value
[100,20] (default) | [width,height]
Size of the button, returned as [width,height]. The units of measurement are pixels.
Parent Parent container of button
app window object (default) | panel object | button group object
Parent container of the button, specified as an app window, panel, or button group object.
Size Size of button
[100,20] (default) | [width,height].
Size of the button, specified as [width,height]. The units of measurement are pixels.
Text Characters that display on button
'Button' (default) | string | cell array of strings
Characters that display on button, specified as one of the following:
string Displayed as a single line string. For example:
5-32
Button Properties
uibutton('Text', 'Press');
cell array of strings Displayed as multiline text. Each row of the cell array is one
line of text. Adjust button Size property value accordingly.
uibutton('Text', {'Press','Here'}, 'Size',[40,40]);
Note: Vertical alignment values appear to have no effect when the button is the default
height.
Visible Button visibility
true (default) | false
5-33
Property Reference
Button visibility, specified as true or false. The Visible property determines whether
the button is displayed on the screen. If the Visible property of a button is set to false,
the entire button is hidden, but you can still specify and access its properties.
5-34
Property Reference
Note Changing the Enabled property of a button group does not change the values of
the Enabled properties of its child components, even though disabling the button group
causes the children to be disabled.
FontAngle Character slant of button group title
'normal' (default) | 'italic'
Character slant of the Button Group title, value specified as 'normal' or 'italic'.
Setting this property to italic selects a slanted version of the font, if it is available on
the app users system.
FontName Font in which to display button group title
'Helvetica' (default) | string
Font in which to display the button group Title property value, specified as a string.
If the specified font is not available to the app user, MATLAB uses 'Helvetica'. If
'Helvetica' is not available, MATLAB uses an available sans serif font.
Example: 'Arial'
FontSize Font size of button group title
12 (default) | positive number
Font size of button group title, specified as a positive number. The units of measurement
are points.
Example: 14
FontWeight Thickness of text characters
'normal' (default) | 'bold'
Thickness of the text characters, specified as one of these values:
'normal' Default weight as defined by the particular font
'bold' Thicker character outlines than 'normal'
Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result
in the normal font weight.
Location Location of button group relative to parent
[100,100] (default) | [x,y]
5-36
Location of button group relative to parent, specified as [x,y], where x and y specify the
coordinates from the lower-left corner of the parent container to the lower-left corner of
the button group. The units of measurement are pixels.
OuterSize Button Group size, including the title bar
[123,106] (default) | [width,height]
The button group size, including the title bar, returned as [width,height]. The units
of measurement are pixels.
Parent Parent container of button group
app window object (default) | panel object | button group object
Parent container of button group, specified as an app window, panel, or button group
object.
SelectedObject Currently selected radio or toggle button
first radio or toggle button in button group (default)
Currently selected radio button or toggle button, specified as a radio button or a toggle
button object.
Get the value of this property to determine which radio or toggle button is currently
selected within the button group.
Set the value of this property to change the currently selected radio or toggle button.
When you change the selection using this property, MATLAB adjusts the Value property
for the other radio or toggle buttons within the button group accordingly.
For example, suppose your button group contains three radio buttons and you set the
SelectedObject property to radiobutton3. MATLAB sets the Value property for each
child radio button as follows:
radiobutton1.Value = false;
radiobutton2.Value = false;
radiobutton3.Value = true;
In other words, setting the SelectedObject property for a button group has the same
effect as setting the Value property for a child button.
SelectionChangeFcn Function that executes when an app user changes the button
selection
[] (default) | function handle | cell array | string
5-37
Property Reference
Function that executes when an app user changes the button selection, specified as one of
these values:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace
This callback function does not execute if a radio or toggle button Value property changes
programmatically.
Example: @function
Example: {@function, x}
Size Button Group size, excluding title bar
[123,85] (default) | [width,height]
The button group size, excluding the title bar, specified as [width,height]. The units
of measurement are pixels.
Title Button Group title
'Button Group' (default) | string | cell array of strings
The button group title, specified as a string.
Visible Button Group visibility
true (default) | false
Button Group visibility, specified as true or false. The Visible property determines
whether the button group is displayed on the screen. If the Visible property of a button
group is set to false, the entire button group is hidden. However, you can still specify
and access its properties.
Note Changing the Visible property of a button group does not change the values of the
Visible properties of its child components, even though hiding the button group causes
the children to be hidden.
5-38
Property Reference
Font size of check box text, specified as a positive number. The units of measurement are
points.
Example: 14
FontWeight Thickness of text characters
'normal' (default) | 'bold'
Thickness of the text characters, specified as one of these values:
'normal' Default weight as defined by the particular font
'bold' Thicker character outlines than 'normal'
Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result
in the normal font weight.
Location Location of check box relative to parent container
[100,100] (default) | [x,y]
Location of check box relative to parent container, specified as [x,y], where x and y
specify the coordinates from the lower-left corner of the parent container (panel or app
window) to the lower-left corner of the Check Box. The units of measurement are pixels.
Example: [100,150]
OuterLocation Location of check box relative to parent container
[100,100] (default) | [x,y]
Identical to Location for Check Boxes.
OuterSize Size of check box, including Text value
[84,15] (default) | [width,height]
Identical to Size for Check Boxes.
Parent Parent container of check box
app window object (default) | panel object | button group object
Parent container of check box, specified as an app window, panel, or button group object.
Size Size of check box, including Text value
[84,15] (default) | [width,height]
5-40
Size of the check box, including the Text value, specified as [width,height]. The units
of measurement are pixels.
Text Check box label
'Check Box' (default) | string | cell array of strings
Check Box label, specified as one of the following:
string Displayed as a single line string. For example:
uicheckbox('Text', 'Filter');
cell array of strings Displayed as multiline text. Each row of the cell array is one
line of text. (You must increase the size from the default value to accommodate the
additional line of text.)
uicheckbox('Text',{'Notch','Filter'},'Size',[84,30]);
If you set the Text property to a cell array of strings, you must change the check box Size
property value to accommodate the additional lines of text.
Value State of check box
false (default) | true
State of check box specified as true or false. When the Value property is set to true,
the check box is checked; when set to false, the check box is not checked.
ValueChangedFcn Function that executes when app user selects or clears check box
[] (default) | function handle | cell array | string
Function that executes when app user selects or clears the check box, specified as one of
these values:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
This callback function does not execute if the check box Value changes programmatically.
Example: @function
Example: {@function, x}
Visible Check Box visibility
true (default) | false
5-41
Property Reference
Check Box visibility, specified as true or false. The Visible property determines
whether the check box is displayed on the screen. If the Visible property of a check box
is set to false, the entire check box is hidden, but you can still specify and access its
properties.
5-42
Property Reference
Location of knob, including tick marks, relative to parent, specified as [x,y]. The units
of measurement are pixels.
OuterSize Size of knob, including state marks and labels
[127,86] (default) | [height,width]
Size of knob, including state marks and labels, returned as [height,width]. The units
of measurement are pixels.
Parent Parent container of discrete knob
app window object (default) | panel object | button group object
Parent container of discrete knob, specified as an app window, panel, or button group
object.
Size Size of knob, exclusive of state marks and labels
[60,60] (default) | [width,height]
Size of knob, exclusive of state marks and labels, specified as [width,height]. The
units of measurement are pixels.
Text Set of discrete knob labels
{'Off','Low','Medium','High'} (default) | 1-by-n cell array of strings
The set of discrete knob labels, specified as a 1-by-n cell array of strings. The cell array
must contain at least two elements. The discrete knob displays as many options as there
are elements in the Text property value. MATLAB labels the knob tick marks using the
cell array values, applied in clockwise order on the knob.
Example: {'Off','Slow','Fast'}
Example: {'1','2','3','4'}
TextData Data associated with each element of the Text property
{1,2,3,4} (default) | 1-by-n cell array of integers
Data associated with each element of the Text property, specified as a 1by-n cell
array of integers, where n is greater than 0. For example, if you set the Text property to
temperature descriptions ('boiling','lukewarm','freezing') you might set the
TextData property to corresponding temperature values ({212, 90, 32} in degrees
in Fahrenheit).
If you change the number of elements in the Text property value, then the TextData
property is updated accordingly, unless you previously explicitly set TextData. If you
5-44
explicitly set the TextData property, then it is not updated automatically when the
number of elements in the Text property changes.
If the TextData property value contains more elements than the Text property value,
then MATLAB ignores the extra TextData property value elements.
If the TextData property value contains fewer elements than the Text property value,
and an app user selects an option that has no corresponding TextData property element,
then MATLAB sets the ValueData property to an empty cell array ({}) and MATLAB
displays a warning at the command prompt.
Value Value to which knob points
element of Text property array
The value to which the discrete knob points, specified as an element of the Text property
array. The default is the first element of the Text property array.
If the Text property array is empty, MATLAB sets the Value property to an empty double
array [].
If the Text property array changes programmatically and the current Value setting is an
element of the Text property array, then the Value remains unchanged.
If the Text property array changes programmatically and the Value setting is no longer
an element of the Text property array, MATLAB sets Value to the first element of the
Text property array.
If the ValueData property changes programmatically, MATLAB updates the Value
property to the Text property array element corresponding to the new selection.
If the Value property changes programmatically to an element in ValueData that
appears more than once in ValueData, then the item selected in the app corresponds to
the first match.
ValueChangedFcn Callback to execute when app user changes the knob control location
[] (default) | function handle | cell array | string
Callback to execute when the app user changes the discrete knob control setting,
specified as one of the following:
Function handle
Cell array containing a function handle and additional arguments
5-45
Property Reference
String that is a valid MATLAB expression, which is evaluated in the base workspace.
Example: @function
Example: {@function, x}
ValueData Data associated with selected value
element of TextData
The data associated with the selected value, specified as an element of the TextData
property value. MATLAB uses isequal to determine if the ValueData property value
matches an element of the TextData property value. If TextData is empty, MATLAB sets
the Value property to an empty double array [].
If you programmatically set the ValueData property value, then the Value property
setting and the selection in the app change accordingly.
If you programmatically set ValueData to an element in TextData that appears more
than once in TextData, then the item selected in the app corresponds to the first match.
If you programmatically change TextData, the current selection in the app does not
change. However, ValueData is updated to the new data of the selected option.
If the Value property setting changes, the ValueData property value is updated to the
data associated with the new value.
Visible Discrete Knob visibility
true (default) | false
Discrete Knob visibility, specified as true or false. The Visible property determines
whether the discrete knob is displayed on the screen. If the Visible property of a discrete
knob is set to false, the entire discrete knob is hidden, but you can still specify and
access its properties.
5-46
Property Reference
Property Reference
The data associated with the selected value, specified as an element of the TextData
property value. MATLAB uses isequal to determine if the ValueData property value
matches an element of the TextData property value. If TextData is empty, MATLAB sets
the Value property to an empty double array [].
If you programmatically set the ValueData property value, then the Value property
setting and the selection in the app change accordingly.
If you programmatically set ValueData to an element in TextData that appears more
than once in TextData, then the item selected in the app corresponds to the first match.
If you programmatically change TextData, the current selection in the app does not
change. However, ValueData is updated to the new data of the selected option.
If the Value property setting changes, the ValueData property value is updated to the
data associated with the new value.
Visible Drop Down visibility
true (default) | false
Drop Down visibility, specified as true or false. The Visible property determines
whether the drop down is displayed on the screen. If the Visible property of a drop down
is set to false, the entire drop down is hidden, but you can still specify and access its
properties.
5-51
Property Reference
Editable
'true'
'true'
'false'
'false'
5-52
Visual Result
Functional Result
Enabled
Editable
'true'
'false'
Visual Result
Functional Result
App user cannot update
the edit field.
Use this combination
of property values
when you want the
text to be easy to read,
even though it is not
editable.
'false'
'true'
Editable Whether edit field is editable
true (default) | false
Whether edit field is editable, specified as true or false.
As shown in the following table, the Enabled property value also affects whether a edit
field is editable.
Enabled
Editable
Visual Result
Functional Result
'true'
'true'
'false'
'false'
'true'
'false'
Property Reference
Enabled
Editable
'false'
'true'
Visual Result
Functional Result
App user cannot update
the edit field.
Alignment of text within the edit field, specified as 'left', 'right', or 'center'. The
alignment affects the display as the app user edits the edit field.
Location Location of edit field relative to parent
[100,100] (default) | [x,y]
Location of edit field relative to parent, specified as [x,y], where x and y specify the
coordinates from the lower-left corner of the parent container to the lower-left corner of
the edit field. The units of measurement are pixels.
OuterLocation Location of edit field relative to parent container
[100,100] (default) | [x,y]
Identical to Location for Edit Fields.
OuterSize Size of edit field
[100,20] (default) | [width,height]
Identical to Size for Edit Fields.
Parent Parent container of edit field
app window object (default) | panel object | button group object
Parent container of the edit field, specified as an app window handle, panel, or button
group object.
Size Size of edit field
[100,20] (default) | [width,height].
Size of the edit field, specified as [width,height]. The units of measurement are
pixels.
Value Text in text field
'' (default) | string
Text in the edit field, specified as a string. MATLAB displays the string as a single line.
If you want to allow multiple lines of text, create a Text Area instead.
Example: 'E. coli'
ValueChangedFcn Callback to execute after text entry or update
[] (default) | function handle | cell array | string
5-55
Property Reference
Callback function to execute after text entry or update, specified as one of these values:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
The callback executes after the app user changes text in the edit field, and then either
presses Enter, or clicks outside the edit field.
Example: @function
Example: {@function, x}
Visible Edit Field visibility
true (default) | false
Edit Field visibility, specified as true or false. The Visible property determines
whether the edit field is displayed on the screen. If the Visible property of a edit field
is set to false, the entire edit field is hidden, but you can still specify and access its
properties.
5-56
Editable
'true'
'true'
Visual Result
Functional Result
App user can edit
text or change the
5-57
Property Reference
Enabled
Editable
Visual Result
Functional Result
selection in the editable
drop down. A callback
associated with the
editable drop down
executes when an
option changes.
'false'
'false'
'true'
'false'
'false'
'true'
Editable
'true'
'true'
'false'
'false'
5-58
Visual Result
Functional Result
Enabled
Editable
Visual Result
Functional Result
'true'
'false'
'false'
'true'
Property Reference
Location of editable drop down relative to parent, specified as [x,y], where x and y
specify the coordinates from the lower-left corner of the parent container to the lower-left
corner of the editable drop down. The units of measurement are pixels.
OuterLocation Location of editable drop down relative to parent container
[100,100] (default) | [x,y]
Identical to Location for editable drop downs.
OuterSize Size of editable drop down
[100, 20] (default) | [width,height]
Identical to Size for editable drop downs.
Parent Parent container of editable drop down
app window object (default) | panel object | button group object
Parent container of editable drop down, specified as an app window, panel, or button
group object.
Size Size of editable drop down
[100 20] (default) | [width, height].
Size of the closed editable drop down, specified as [width, height]. The units of
measurement are pixels.
Text Set of editable drop down options presented to app user
{'Option 1','Option 2','Option 3','Option 4'} (default) | 1-by-n cell array of
strings
The set of editable drop down labels, specified as a 1-by-n cell array of strings. The
editable drop down displays as many options as there are elements in the Text property
value.
Example: {'Centigrade','Farenheit','kelvin'}
Example: {'1','2','3'}
TextData Set of Editable Drop Down values
{1, 2, 3, 4} (default) | 1-by-n cell array
Data associated with each element of the Text property, specified as a 1-by-n cell array
of integers, where n is greater than 0. For example, if you set the Text property to
5-60
employee names, you might set the TextData property to corresponding employee id
numbers.
If you change the number of elements in the Text property value, then the TextData
property is updated accordingly, unless you previously explicitly set TextData. If you
explicitly set the TextData property, then it is not updated automatically when the
number of elements in the Text property changes.
If the TextData property value contains more elements than the Text property value,
then MATLAB ignores the extra TextData property value elements.
If the TextData property value contains fewer elements than the Text property value,
and an app user selects an option that has no corresponding TextData property element,
then MATLAB sets the ValueData property to an empty cell array ({}) and displays a
warning at the command prompt.
Example: {'Red' 'Green' 'Blue'}
Example: {'10' '20' '30' '40'}
Value Selected or typed value
'Option 1' (default) | element of Text property cell array | string
Selected or typed value, specified as an element of the Text property cell array or an app
user-entered string.
If the Text property array is empty, MATLAB sets the Value property to the user-entered
string or an empty double array [] when no string is entered.
If an app user types a string in the Editable Drop Down, the Value property setting
becomes that string, the Text and TextData property value remains unchanged, and the
ValueData property value is an empty vector.
If the Text property array changes programmatically and the current Value setting is an
element of the Text property array, then the Value remains unchanged.
If the Text property array changes programmatically and the Value setting is no longer
an element of the Text property array, then MATLAB sets Value to the first element of
the Text property array.
If the ValueData property changes programmatically, MATLAB updates the Value
property to the Text property array element corresponding to the new selection.
5-61
Property Reference
Editable Drop Down visibility, specified as true or false. The Visible property
determines whether the editable drop down is displayed on the screen. If the Visible
property of a editable drop down is set to false, the entire editable drop down is hidden,
but you can still specify and access its properties.
5-63
Property Reference
Gauge Properties
Control gauge appearance and behavior
Gauges are app components that represent a measurement instrument. Properties
control the appearance and behavior of a particular instance of a gauge. To modify
aspects of a gauge, change property values. Use dot notation to refer to a particular
object and property:
gauge = uigauge;
val = gauge.Value;
gauge.Value = 45;
Gauge Properties
Property Reference
'manual'- You specify the major tick labels by specifying the MajorTickLabels
property value.
MajorTicksMode Major tick creation mode
'auto' (default) | 'manual'
Major tick creation mode, specified as one of the following:
'auto' MATLAB populates the MajorTicks property value by creating several
major tick marks in the range specified by the Limits property (inclusive).
'manual'- You specify the major ticks by specifying the MajorTicks property value.
MinorTicks Minor tick values
[0:4:100] (default) | numeric array
Minor tick values, specified as a numeric array. Any MinorTicks elements that fall
outside Limits are not displayed on the gauge. If a minor tick falls on the same value as
a major tick, only the major tick is displayed. MATLAB removes duplicate MinorTicks
element values. Setting the MinorTicks property value sets the MinorTicksMode
property value to 'manual'.
To exclude minor ticks from the gauge, specify an empty array.
MinorTicksMode Minor tick creation mode
'auto' (default) | 'manual'
Minor tick creation mode, specified as one of the following:
'auto' Minor ticks display at positions around the gauge determined by
calculating the difference between the largest major tick interval between any two
major consecutive major ticks and dividing it by five. For example, if major ticks are
uniformly distributed, the resulting gauge has four minor ticks between every major
tick.
Minor ticks depend only on the visible major ticks (that is, Major Ticks within scale
limits).
MATLAB does not generate minor ticks for Major Ticks that are beyond scale limits.
When the Limits property value changes, minor ticks are updated to populate the full
scale range (the MinorTicks property is updated accordingly).
5-66
Gauge Properties
'manual'- You specify the MinorTicks property numeric array. The MinorTicks
property value does not change size or content on its own.
OuterLocation Location of gauge relative to parent container
[100,100] (default) | [x,y]
Identical to Location for Gauges.
OuterSize Size of gauge
[120,120] (default) | [width,height]
Identical to the Size property for Gauges.
Parent Parent container of gauge
app window object (default) | panel object | button group object
Parent container of gauge, specified as an app window, panel, or button group object.
ScaleColorLimits Range of values specifying start and end of colored scale regions
[ ] (default) | array
Range of values specifying start and end of colored scale regions, specified as a n-by-2
array of numeric values. For every row in the array, the first element must be less than
the second element.
When applying colors to the gauges scale, MATLAB applies the colors starting at the
first row in the ScaleColors property value. Therefore, if two rows in ScaleColorLimits
property value overlap, then the color applied later takes precedence.
A gauge does not display any portion of a ScaleColorLimits property value element that
falls outside of Limits property value.
If ScaleColors and ScaleColorLimits property values are different sizes, then the gauge
shows only the colors that have matching limits. For example, if the ScaleColors property
value has 3 rows, but the ScaleColorLimits property value has only 2 rows, the gauge
displays the first two color/ limit pairs only.
Example: [10,20; 20,30]
ScaleColors Colors that appear on gauge scale
[ ] (default) | RGB triplet | predefined color name | 1-by-n cell array
Colors that appear on gauge scale, specified as one of the following:
5-67
Property Reference
An n-by-3 array of RGB values, where each element is a valid RGB value between 0
and 1.
A 1-by-n cell array, where each element is a color name or an RGB triplet. The cell
array can contain a mix of RGB triplets and color names.
MATLAB stores and returns all color names and RGB triplets as an n-by-3 array.
An RGB triplet is a three-element row vector whose elements specify the intensities of
the red, green, and blue components of the color. The intensities must be in the range
[0,1], for example, [0.4 0.6 0.7]. This table lists RGB triplet values that have
equivalent color strings.
Long Name
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
Each row of the ScaleColors array represents the color for the i the colored scale region.
If you set ScaleColors property without explicitly setting ScaleColorLimits property,
then MATLAB determines the ScaleColorLimits property value by creating n equally
spaced, nonoverlapping limits that span the gauges entire scale. For example,
if the Limits property value is [0,75], and the ScaleColors property value is
{'green','yellow','red'}, then MATLAB sets ScaleColorLimits to [0,25;
25,50; 50,75]
Similarly, if you change Limits, without explicitly setting ScaleColorLimits, then
MATLAB sets the ScaleColorLimits property value as described in the preceding
paragraph.
Example: {'blue','green'}
Example: {[0,.5,.2], 'green'}
5-68
Gauge Properties
5-69
Property Reference
Knob Properties
Control knob appearance and behavior
Knobs are app components representing instrument control knobs that app users can
adjust to control a value. Properties control the appearance and behavior of a particular
instance of a knob. To modify aspects of a knob, change property values. Use dot notation
to refer to a particular object and property:
knob = uiknob;
knob.Value = 45;
val = knob.Value;
Knob Properties
Likewise, if you change Limits such that the knob Value is greater than the new upper
limit, MATLAB sets the Value to the new upper limit.
Location Location of knob, exclusive of tick marks, relative to parent
[126,111] (default) | [x,y]
Location of knob, exclusive of tick marks, relative to parent, specified as [x,y], where
x and y specify the coordinates from the lower-left corner of the parent container to the
lower-left corner of the knob. The units of measurement are pixels.
MajorTicks Major tick mark values
[0,10,20,30,40,50,60,70,80,90,100] (default) | array of numeric values
Major tick mark values, specified as an array of numeric values. Each value must be
equal to or greater than 0. Any array values that fall outside Limits are not displayed on
the knob. MATLAB removes duplicate array values.
Setting the MajorTicks property value sets the MajorTicksMode property value to
'manual'.
MajorTickLabels Labels on each major tick mark
{'0','10','20','30','40','50','60','70','80','90','100'} (default) | cell
array of strings
Labels on each major tick mark, specified as a cell array of strings. MATLAB uses each
element as the label for the corresponding major tick mark.
Setting MajorTickLabels changes the MajorTickLabelsMode value to 'manual'.
To create a blank label to a major tick, specify an empty string for that ticks
corresponding MajorTickLabels element.
If you specify more MajorTickLabels elements than MajorTicks elements, MATLAB
ignores the extra labels.
If you specify fewer MajorTickLabels elements than MajorTicks elements, MATLAB
leaves the extra ticks unlabeled.
Example: {'high','medium', 'low'}
MajorTickLabelsMode Major tick labels creation mode
'auto' (default) | 'manual'
5-71
Property Reference
Knob Properties
When the Limits value changes, minor ticks are updated to populate the full scale
range (the MinorTicks property is updated accordingly).
'manual'- You specify the MinorTicks numeric array. The MinorTicks value does not
change size or content on its own.
OuterLocation Location of knob, including tick marks, relative to parent
[100,104] (default) | [x,y]
Location of knob, including tick marks, relative to parent, specified as [x,y]. The units
are pixels.
OuterSize Size of knob, including tick marks
[112,100] (default) | [height,width]
Size of knob, including tick marks, returned as [height,width].
Parent Parent container of knob
app window object (default) | panel object | button group object
Parent container of knob, specified as an app window handle, panel, or button group
object.
Size Size of knob, exclusive of tick marks
[60,60] (default) | [width,height]
Size of knob, exclusive of tick marks, specified as [width,height].
Value Knob value
0 (default) | numeric
The knob value, specified as a numeric. The numeric value must be within the range
specified for Limits.
ValueChangedFcn Callback function to execute when app user changes knob value
[] (default) | function handle | cell array | string
Callback function to execute once when an app user changes the knob value (by dragging
and releasing the knob), specified as one of these values:
Function handle
Cell array containing a function handle and additional arguments
5-73
Property Reference
String that is a valid MATLAB expression, which is evaluated in the base workspace.
Example: @function
Example: {@function, x}
ValueChangingFcn Callback function to execute as the app user changes knob value
[] (default) | function handle | cell array | string
The callback function to execute as the app user changes the knob value, specified as one
of these values:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
When an app user drags the knob, MATLAB generates event data and stores it in the
event Value property, which you can query.
For example, to display the event value in the MATLAB Command Window, specify this
code in the ValueChangingFcn callback:
disp(event.Value)
Knob Properties
Knob visibility, specified as true or false. The Visible property determines whether
the knob is displayed on the screen. If the Visible property of a knob is set to false, the
entire knob is hidden, but you can still specify and access its properties.
5-75
Property Reference
Label Properties
Control label appearance
Labels are app components that use text to identify other components or specify the
purpose of those other components. To modify aspects of a label, change property values.
Use dot notation to refer to a particular object and property:
label = uilabel;
label.Text = 'Type:';
txt = label.Text;
Label Properties
Property Reference
However, MATLAB does not automatically interpret and render text such as this:
label = uilabel('Text', 'Line 1\nLine2', 'Size',[100,150])
Example: 'Threshold'
Example: {'Threshold' 'Value'}
5-78
Label Properties
5-79
Property Reference
Lamp Properties
Control lamp appearance
Lamps are app components that indicate state using color. Lamp properties control
the appearance of a particular instance of a lamp. To modify aspects of a lamp, change
property values. Use dot notation to refer to a particular object and property:
lamp = uilamp;
color = lamp.Color;
lamp.Color = 'red';
5-80
Long Name
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
Lamp Properties
Regardless of how you specify the colors, MATLAB stores and returns them as RGB
triplets. For example:
lamp = uilamp('Color','blue');
x = lamp.Color
ans =
0
Example: [0,1,0]
Example: 'g'
Example: 'green'
Enabled Operational state of lamp
true (default) | false
Operational state of lamp, specified as true or false.
If you set this property to true, the lamp appears bright, indicating that the lamp is
operational.
If you set this property to false, the Lamp appears dimmed.
Location Location of lamp relative to parent
[100,100] (default) | [x,y]
Location of lamp relative to parent, specified as [x,y], where x and y specify the
coordinates from the lower-left corner of the parent container to the lower-left corner of
the lamp. The units of measurement are pixels.
OuterLocation Location of lamp relative to parent container
[100,100] (default) | [x,y]
Identical to Location for Lamps.
OuterSize Size of lamp
[20,20] (default) | [width,height]
Identical to Size for Lamps.
Parent Parent container of lamp
app window object (default) | panel object | button group object
5-81
Property Reference
Parent container of lamp, specified as an app window, panel, or button group object.
Size Size of lamp
[20,20] (default) | [width,height].
Size of the lamp, specified as [width, height]. The units of measurement are pixels.
Visible Lamp visibility
true (default) | false
Lamp visibility, specified as true or false. The Visible property determines whether
the lamp is displayed on the screen. If the Visible property of a lamp is set to false, the
entire lamp is hidden, but you can still specify and access its properties.
5-82
Property Reference
Property Reference
A 1-by-n cell array, where each element is a color name or an RGB triplet. The cell
array can contain a mix of RGB triplets and color names.
MATLAB stores and returns all color names and RGB triplets as an n-by-3 array.
An RGB triplet is a three-element row vector whose elements specify the intensities of
the red, green, and blue components of the color. The intensities must be in the range
[0,1], for example, [0.4 0.6 0.7]. This table lists RGB triplet values that have
equivalent color strings.
Long Name
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
Each row of the ScaleColors array represents the color for the ith colored scale region.
If you set ScaleColors property without explicitly setting ScaleColorLimits property,
then MATLAB determines the ScaleColorLimits property value by creating n equally
spaced, nonoverlapping limits that span the linear gauges entire scale. For example, if
the Limits property value is [0,75], and the ScaleColors property value is {'green',
'yellow', 'red'}, then MATLAB sets ScaleColorLimits to [0,25; 25,50; 50,75]
Similarly, if you change Limits, without explicitly setting ScaleColorLimits, then
MATLAB sets the ScaleColorLimits property value as described in the preceding
paragraph.
Example: {'blue', 'green'}
Example: {[0,.5,.2], 'green'}
Example: {[0,.5,.2], [.2,.6,0]}
Size Size of linear gauge
[120,40] (default) | [width,height]
5-87
Property Reference
Size of the linear gauge, specified as [width,height]. The units of measurement are
pixels.
Value gauge needle location
0 (default) | numeric
The linear gauge needle location, specified as any numeric value. If the value is less than
the minimum Limits property value, then the needle points to a location immediately
before the beginning of the scale. If the value is more than the maximum Limits property
value, then the needle points to a location immediately after the end of the scale.
Changing the Limits property value has no effect on the Value property setting.
Example: 60
Visible Linear Gauge visibility
true (default) | false
Linear Gauge visibility, specified as true or false. The Visible property determines
whether the linear gauge is displayed on the screen. If the Visible property of a linear
gauge is set to false, the entire linear gauge is hidden, but you can still specify and
access its properties.
5-88
Property Reference
If the Multiselect property is set to false, then the ValueData property is set to
an empty cell array ({}).
an empty double array if the Multiselect property value is false,
TextData Set of List Box values
{1, 2, 3, 4} (default) | 1-by-n cell array | empty cell array ({})
The set of list box values, specified as a 1-by-n cell array or an empty cell array.
Duplicate elements are allowed.
If the number of elements in the Text property changes, MATLAB automatically updates
the TextData cell array to {1, 2, 3, N}, where N is the number of elements in the Text
property cell array. However, if you explicitly set the TextData property, it ceases to
update automatically as the Text property cell array changes.
Example: {'Red', 'Green', 'Blue'}
Example: {10, 20, 30, 40}
Example: {true, false}
Value List Box selection
'Item 1' (default) | element or elements of Text property cell array
List Box selection, specified as an element or elements (if the Multiselect property is set
to true) of the Text property cell array.
The default is the first element of the Text property cell array. The Value property
setting must be an element of the Text property cell array, as determined by isequal.
If the Text property cell array is empty, MATLAB sets the Value property depending on
the value of the Multiselect property, as follows:
If the Multiselect property is set to false, MATLAB sets the Value property to an
empty double array [].
If the Multiselect property is set to true, MATLAB sets the Value property to an
empty cell array ({}).
Setting the Value property updates the selection displaying in the running app.
Therefore, if Value is set to an element that appears more than once in the Text property
cell array, then the selected item corresponds to the first match.
5-91
Property Reference
If the Multiselect property is set to true, then the selected items correspond to the
elements that match. The matching elements can be repeated in the Value property
value up to the number of times they appear in the Text property cell array.
If code changes the Text property cell array elements, it has one of the following effects:
If the currently selected option in the running app is an element of the updated Text
property cell array, then the Value property setting remain unchanged.
If the currently selected value in a running app is not an element of the updated Text
cell array, then MATLAB sets the Value property to the first element of the Text
property cell array.
If the ValueData property changes, MATLAB updates the Value property to the Text cell
array element corresponding to the new ValueData property value.
ValueChangedFcn Callback function that executes when app user changes list box
selections
[] (default) | function handle | cell array | string
Callback function that executes when app user changes list box selections, specified as
one of the following:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
Example: @function
Example: {@function, x}
ValueData Data associated with the list box selection
1 (default) | element of TextData
Data associated with the list box selection, specified as an element or elements (if the
Multiselect property is set to true) of the TextData property cell array.
If the TextData property cell array is empty, valid values for the ValueData property
depends on the MultiSelect property value, as follows:
If the Multiselect property is set to false, the ValueData property must be an empty
double array [].
5-92
If the Multiselect property is set to true, the ValueData property must be an empty
cell array ({}).
Visible List Box visibility
true (default) | false
List Box visibility, specified as true or false. The Visible property determines whether
the list box is displayed on the screen. If the Visible property of a list box is set to false,
the entire list box is hidden, but you can still specify and access its properties.
5-93
Property Reference
If the orientation of the gauge is such that a rounded edge is closest to the lower left
corner of the parent container, thenx and y specify the coordinates to the southwest
corner of an imaginary box surrounding the gauge.
MajorTicks Major tick mark values
[0,50,100] (default) | array of numeric values
Major tick mark values, specified as an array of numeric values. Each value must be
equal to or greater than 0. Any array values that fall outside Limits property value are
not displayed on the ninety degree gauge. MATLAB removes duplicate array values.
Setting the MajorTicks property value sets the MajorTicksMode property value to
'manual'.
MajorTickLabels Major tick mark labels
{'0', ''50','100']} (default) | cell array of strings
Major tick mark labels, specified as a cell array of strings. MATLAB uses each element
as the label for the corresponding major tick mark.
Setting the MajorTickLabels property value changes the MajorTickLabelsMode property
value to 'manual'.
To create a blank label to a major tick, specify an empty string for the corresponding
MajorTickLabels property value element.
If you specify more MajorTickLabels property value elements than MajorTicks property
value elements, MATLAB ignores the extra labels.
If you specify fewer MajorTickLabels property value elements than MajorTicks property
value elements, MATLAB leaves the extra ticks unlabeled.
MajorTickLabelsMode Major tick label creation mode
'auto' (default) | 'manual'
Major tick label creation mode, specified as one of the following:
'auto' MATLAB creates a cell array of strings to populate the major tick labels.
MATLAB transforms each numeric major tick element to a string using num2str.
'manual' You specify the major tick labels by specifying the MajorTickLabels
property value.
MajorTicksMode Major tick creation mode
'auto' (default) | 'manual'
5-95
Property Reference
'northwest'
'northeast'
'southwest'
'southeast'
Property Reference
When applying colors to the ninety degree gauges scale, MATLAB applies the colors
starting at the first row in the ScaleColors property value. Therefore, if two rows in
ScaleColorLimits property value overlap, then the color applied later takes precedence.
A gauge does not display any portion of a ScaleColorLimits property value element that
falls outside of Limits property value.
If ScaleColors and ScaleColorLimits property values are different sizes, then the gauge
shows only the colors that have matching limits. For example, if the ScaleColors property
value has 3 rows, but the ScaleColorLimits property value has only 2 rows, the gauge
displays the first two color/ limit pairs only.
Example: [10,20; 20,30]
ScaleColors Colors that appear on gauge scale
[ ] (default) | RGB triplet | predefined color name | 1-by-n cell array
Colors that appear on ninety degree gauge scale, specified as one of the following:
An n-by-3 array of RGB values, where each element is a valid RGB value between 0
and 1
A 1-by-n cell array, where each element is a color name or an RGB triplet. The cell
array can contain a mix of RGB triplets and color names.
MATLAB stores and returns all color names and RGB triplets as an n-by-3 array.
An RGB triplet is a three-element row vector whose elements specify the intensities of
the red, green, and blue components of the color. The intensities must be in the range
[0,1], for example, [0.4 0.6 0.7]. This table lists RGB triplet values that have
equivalent color strings.
5-98
Long Name
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
Long Name
Short Name
RGB Triplet
'black
'k'
[0 0 0]
Each row of the ScaleColors array represents the color for the ith colored scale region.
If you set ScaleColors property without explicitly setting ScaleColorLimits property, then
MATLAB determines the ScaleColorLimits property value by creating n equally spaced,
nonoverlapping limits that span the ninety degree gauges entire scale. For example, if
the Limits property value is [0,75], and the ScaleColors property value is {'green',
'yellow', 'red'}, then MATLAB sets ScaleColorLimits to [0,25; 25,50; 50,75]
Similarly, if you change Limits, without explicitly setting ScaleColorLimits, then
MATLAB sets the ScaleColorLimits property value as described in the preceding
paragraph.
Example: {'blue', 'green'}
Example: {[0,.5,.2], 'green'}
Example: {[0,.5,.2], [.2,.6,0]}
ScaleDirection Direction of scale
'clockwise' (default) | 'counterclockwise'
Direction of scale, specified as one of the following:
'clockwise' The scale appears such that the scale tick values increase in a
clockwise manner.
'counterclockwise' The scale appears such that the scale tick values increase
in a counterclockwise manner.
Size Size of ninety degree gauge
[60,60] (default) | [width,height].
Size of the ninety degree gauge, specified as [width,height]. The width and height of
the gauge is determined by the length of the two straight edges of the gauge, regardless
of orientation. The units of measurement are pixels.
Value gauge needle location
0 (default) | numeric
The ninety degree gauge needle location, specified as any numeric value. If the value
is less than the minimum Limits property value, then the needle points to a location
5-99
Property Reference
immediately before the beginning of the scale. If the value is more than the maximum
Limits property value, then the needle points to a location immediately after the end of
the scale.
Changing the Limits property value has no effect on the Value property setting.
Example: 60
Visible Ninety Degree Gauge visibility
true (default) | false
Ninety Degree Gauge visibility, specified as true or false. The Visible property
determines whether the ninety degree gauge is displayed on the screen. If the Visible
property of a ninety degree gauge is set to false, the entire ninety degree gauge is
hidden, but you can still specify and access its properties.
5-100
Editable
Visual Result
Functional Result
'true'
'true'
'false'
'false'
Property Reference
Enabled
Editable
Visual Result
Functional Result
'true'
'false'
'false'
'true'
Editable
Visual Result
Functional Result
'true'
'true'
'false'
'false'
'true'
'false'
'false'
'true'
'left' Numbers align on the left side of the numeric edit field.
5-102
5-103
Property Reference
Whether Value can be equal to the Limits property upper value, specified as one of the
following:
true Value property setting must be equal to or less than the upper limit
false Value property setting must be less than the upper limit
For example, if you want the numeric input to be between 0 and 1, excluding 0 and 1, set
the Limit property value to [0,1], the UpperLimitInclusivity property to false and the
LowerLimitInclusivity property to false.
Value Value in numeric edit field
0 (default) | double-precision number
Value in the numeric edit field, specified as a double-precision number.
When an app user types or changes a value in the numeric edit field it is a string. When
the user presses the Enter key or changes focus, MATLAB converts the user-entered
string to a double-precision number.
MATLAB rejects the value if:
It cannot convert the string to a scalar number.
The value is NaN, blank, or a complex number.
The value is a mathematical expression, such as 1 + 2.
The value is less than the Limit property lower limit or greater than the upper limit.
When MATLAB rejects a user-entered value, a tooltip appears describing the value
requirements. The edit field text immediately reverts to the previous numeric edit field
value. In this case, no ValueChangedFcn fires.
Example: 10
ValueChangedFcn Code to execute when app user changes numeric edit field value
function handle (default) | function handle | cell array | string
Code to execute when app user changes the numeric edit field value, specified as one of
these values:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
5-105
Property Reference
This function executes whenever an app user changes the value in the numeric edit
field and changes focus or presses the Enter key. This function does not execute if the
numeric edit field value changes programmatically.
Example: @function-name
Example: {@function-name, argument}
ValueDisplayFormat Format of numeral in edit field
'%11.4g' (default) | format string
The format of the numeral in the numeric edit field, specified as a format string.
MATLAB uses num2str(NumericDisplayFormat,Value) to convert the edit field
Value property to a string and displays it.
You can mix text with format strings. For example:
numfield = uieditfield('numeric','ValueDisplayFormat','%.0f MS/s');
When the user clicks in the numeric edit field, the field shows the value without the
string.
For a complete list of supported format strings, see num2str in the MATLAB
documentation.
Example: '%.0f MS/s'
Visible Numeric Edit Field visibility
true (default) | false
Numeric Edit Field visibility, specified as true or false. The Visible property
determines whether the numeric edit field is displayed on the screen. If the Visible
property of a numeric edit field is set to false, the entire numeric edit field is hidden,
but you can still specify and access its properties.
5-106
Panel Properties
Panel Properties
Control panel appearance
Panels are app components that contain other components. Typically, you use them to
organize components in your app. Properties control the appearance and behavior of a
particular instance of a panel. To modify aspects of a panel, change property values. Use
dot notation to refer to a particular object and property:
window = appwindow;
panel = matlab.ui.control.Panel('Parent', window);
title = panel.Title;
panel.Title = 'Display Options';
Property Reference
You cannot add or remove children components using the Children property of the
panel. Use this property to view the list of children or to reorder the children. The
order of the children in this array reflects the front-to-back order (stacking order) of the
components on the screen.
To add a child to this list, set the Parent property of the child component to this panel.
Enabled Operational status of panel
true (default) | false
Visual appearance of panel, specified as
true Panel and its child components (unless you disable a child component within
it) appear operational.
false Panel and its child components appear dimmed and you cannot manipulate
any components within it.
Note Changing the Enabled property of a panel does not change the values of the
Enabled properties of its child components, even though disabling the panel causes the
children to be disabled.
FontAngle Character slant of panel title
'normal' (default) | 'italic'
Character slant of the Panel title, specified as 'normal' or 'italic'. Setting this
property to italic selects a slanted version of the font, if it is available on the app users
system.
FontName Font in which to display panel title
'Helvetica' (default) | string
Font in which to display the panel Title property value, specified as a string. If
the specified font is not available to the app user, MATLAB uses 'Helvetica'. If
'Helvetica' is not available, MATLAB uses an available sans serif font.
Example: 'Arial'
FontSize Font size of panel title
12 (default) | positive number
5-108
Panel Properties
Font size of panel title, specified as a positive number. The units of measurement are
points.
Example: 14
FontWeight Thickness of text characters
'normal' (default) | 'bold'
Thickness of the text characters, specified as one of these values:
'normal' Default weight as defined by the particular font
'bold' Thicker character outlines than 'normal'
Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result
in the normal font weight.
Location Location of panel relative to parent
[100,100] (default) | [x,y]
Location of panel relative to parent, specified as [x,y], where x and y specify the
coordinates from the lower-left corner of the parent container to the lower-left corner of
the panel. The units of measurement are pixels.
OuterLocation Location of panel relative to parent container
[100,100] (default) | [x,y]
Identical to Location for Panels.
OuterSize Panel size, including the title bar
[260,221] (default) | [width,height]
The panel size, including the title bar, returned as [width,height]. The units of
measurement are pixels.
Parent Parent container of panel
app window object (default) | panel object | button group object
Parent container of panel, specified as an app window, panel, or button group object.
Size Panel size, excluding the title bar
[260,200] (default) | [width,height]
The panel size, excluding the title bar, specified as [width,height]. The units of
measurement are pixels.
5-109
Property Reference
5-110
Note: To specify how you want your app to respond when a user changes a radio button
selection, code the ValueChangedFcn callback for the Button Group to which the radio
buttons are parented.
Enabled Operational state of radio button
true (default) | false
Operational state of radio button, specified as true or false.
If you set this property to true, the appearance of the radio button indicates that an app
user can select it.
If you set this property to false, the appearance of the radio button appears dimmed,
indicating that an app user cannot select it.
FontAngle Character slant of radio button text
'normal' (default) | 'italic'
Character slant of the radio button text, specified as 'normal' or 'italic'. Setting
this property to italic selects a slanted version of the font, if it is available on the app
users system.
FontName Font in which to display radio button text
'Helvetica' (default) | string
5-111
Property Reference
Font in which to display the radio button Text property value, specified as a string.
If the specified font is not available to the app user, MATLAB uses 'Helvetica'. If
'Helvetica' is not available, MATLAB uses an available sans serif font.
Example: 'Arial'
FontSize Font size of radio button text
12 (default) | positive number
Font size of radio button text, specified as a positive number. The units of measurement
are points.
Example: 14
FontWeight Thickness of text characters
'normal' (default) | 'bold'
Thickness of the text characters, specified as one of these values:
'normal' Default weight as defined by the particular font
'bold' Thicker character outlines than 'normal'
Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result
in the normal font weight.
Location Location of radio button relative to button group
[10,10] (default) | [x,y]
Location of the radio button relative to the parent button group container, specified as
[x,y], where x and y specify the coordinates from the lower-left corner of the button
group container to the lower-left corner of the Radio Button. The units of measurement
are pixels.
OuterLocation Location of radio button relative to parent container
[10,10] (default) | [x,y]
Identical to Location for Radio Buttons.
OuterSize Size of radio button, including text
[123,106] (default) | [width, height]
Identical to Size for Radio Buttons.
5-112
Property Reference
button is set to false, the entire radio button is hidden, but you can still specify and
access its properties.
5-114
Property Reference
The rocker switch points down when the Orientation property is set to 'vertical'.
It points left when the Orientation property is set to 'horizontal'.
true
The rocker switch points up when the Orientation property is set to 'vertical'. It
points right when the Orientation property is set to 'horizontal'.
ValueChangedFcn Code to execute when app user flips rocker switch
[] (default) | function handle | cell array | string
Code to execute when app user flips the rocker switch control, specified as one of the
following:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
The app user can change the rocker switch state by clicking and releasing the mouse
button anywhere on the rocker switch (including the state labels), or by clicking on the
rocker switch, dragging, and then releasing the mouse button while still on the rocker
switch.
Example: @function
Example: {@function, x}
Visible Rocker Switch visibility
true (default) | false
Rocker Switch visibility, specified as true or false. The Visible property determines
whether the rocker switch is displayed on the screen. If the Visible property of a rocker
switch is set to false, the entire rocker switch is hidden, but you can still specify and
access its properties.
5-117
Property Reference
If the orientation of the gauge is such that a rounded edge is closest to the lower left
corner of the parent container, thenx and y specify the coordinates to the southwest
corner of an imaginary box surrounding the gauge.
MajorTicks Major tick mark values
[0,10,20,30,40,50,60,70,80,90,100] (default) | array of numeric values
Major tick mark values, specified as an array of numeric values. Each value must be
equal to or greater than 0. Any array values that fall outside Limits property value are
not displayed on the semicircular gauge. MATLAB removes duplicate array values.
Setting the MajorTicks property value sets the MajorTicksMode property value to
'manual'.
MajorTickLabels Major tick mark labels
{'0','10','20','30','40','50','60','70','80','90','100'} (default) | cell
array of strings
Major tick mark labels, specified as a cell array of strings. MATLAB uses each element
as the label for the corresponding major tick mark.
Setting the MajorTickLabels property value changes the MajorTickLabelsMode property
value to 'manual'.
To create a blank label to a major tick, specify an empty string for the corresponding
MajorTickLabels property value element.
If you specify more MajorTickLabels property value elements than MajorTicks property
value elements, MATLAB ignores the extra labels.
If you specify fewer MajorTickLabels property value elements than MajorTicks property
value elements, MATLAB leaves the extra ticks unlabeled.
MajorTicksMode Major tick creation mode
'auto' (default) | 'manual'
Major tick creation mode, specified as one of the following:
'auto' MATLAB populates the MajorTicks property value by creating several
major tick marks in the range specified by the Limits property (inclusive).
'manual' You specify the major ticks by specifying the MajorTicks property value.
5-119
Property Reference
'south'
'east'
'west'
Property Reference
[0,1], for example, [0.4 0.6 0.7]. This table lists RGB triplet values that have
equivalent color strings.
Long Name
Short Name
RGB Triplet
'yellow'
'y'
[1 1 0]
'magenta'
'm'
[1 0 1]
'cyan'
'c'
[0 1 1]
'red'
'r'
[1 0 0]
'green'
'g'
[0 1 0]
'blue'
'b'
[0 0 1]
'white'
'w'
[1 1 1]
'black
'k'
[0 0 0]
Each row of the ScaleColors array represents the color for the ith colored scale region.
If you set ScaleColors property without explicitly setting ScaleColorLimits property, then
MATLAB determines the ScaleColorLimits property value by creating n equally spaced,
nonoverlapping limits that span the semicircular gauges entire scale. For example, if
the Limits property value is [0,75], and the ScaleColors property value is {'green',
'yellow', 'red'}, then MATLAB sets ScaleColorLimits to [0,25; 25,50; 50,75]
Similarly, if you change Limits, without explicitly setting ScaleColorLimits, then
MATLAB sets the ScaleColorLimits property value as described in the preceding
paragraph.
Example: {'blue','green'}
Example: {[0,.5,.2],'green'}
Example: {[0,.5,.2], [.2,.6,0]}
ScaleDirection Direction of scale
'clockwise' (default) | 'counterclockwise'
Direction of scale, specified as one of the following:
'clockwise' The scale appears such that the scale tick values increase in a
clockwise manner.
'counterclockwise' The scale appears such that the scale tick values increase
in a counterclockwise manner.
5-123
Property Reference
5-124
Slider Properties
Slider Properties
Control slider appearance and behavior
Sliders are app components that allow users to select a value along a continuum.
Typically, sliders generate an action when an app user changes the value. Properties
control the appearance and behavior of a particular instance of a slider. To modify
aspects of a slider, change property values. Use dot notation to refer to a particular object
and property:
slider = uislider;
val = slider.Value;
slider.Value = 20;
Property Reference
Slider Properties
Labels on each major tick mark, specified as a cell array of strings. MATLAB uses each
element as the label for the corresponding major tick mark.
Setting MajorTickLabels changes the MajorTickLabelsMode value to 'manual'.
To create a blank label to a major tick, specify an empty string for that ticks
corresponding MajorTickLabels element.
If you specify more MajorTickLabels elements than MajorTicks elements, MATLAB
ignores the extra labels.
If you specify fewer MajorTickLabels elements than MajorTicks elements, MATLAB
leaves the extra ticks unlabeled.
Example: {'100','80','60','40','20','0'}
Example: {'Min','Max'}
MajorTickLabelsMode Major tick labels creation mode
'auto' (default) | 'manual'
Major tick creation mode, specified as one of the following:
'auto' MATLAB creates a cell array of strings to populate MajorTickLabels.
MATLAB transforms each numeric major tick element to a string using num2str.
'manual' You specify the MajorTickLabels cell array of strings.
MajorTicksMode Major tick creation mode
'auto' (default) | 'manual'
Major tick creation mode, specified as one of the following:
'auto' MATLAB populates MajorTicks by creating several major tick marks in
the range specified by the Limits property (inclusive).
'manual' You specify the MajorTicks value array.
MinorTicks Minor tick mark values
[0:5:100] (default) | numeric vector
Minor tick mark values, specified as a numeric vector. Any MinorTicks elements that fall
outside Limits are not displayed on the gauge. If a minor tick falls on the same value as
a major tick, only the major tick is displayed. MATLAB removes duplicate MinorTicks
5-127
Property Reference
element values. Setting the MinorTicks property value sets the MinorTicksMode
property value to 'manual'.
MinorTicksMode Minor tick creation mode
'auto' (default) | 'manual'
Minor tick creation mode, specified as 'auto' or 'manual'.
When MinorTicksMode is set to 'auto', MATLAB determines the placement of minor
ticks by finding the largest interval between two consecutive major ticks and dividing
that interval by 4. For example, if major ticks are uniformly distributed, then the slider
will have 3 minor ticks between every major tick.
Orientation Direction in which slider is displayed
'horizontal' (default) | 'vertical'
Direction in which slider is displayed, specified as 'horizontal' or 'vertical'.
OuterLocation Location of slider, including tick marks and state labels, relative to parent
[93, 72] (default) | [x,y]
Location of slider, including tick marks and state labels, relative to parent, returned as
[x,y], where x and y specify the coordinates from the lower-left corner of the parent
container to the lower-left corner of the slider. The units of measurement are pixels.
OuterSize Size of Slider, including tick marks and labels
[136,40] (default) | [width,height]
Size of the slider, including tick marks and labels, returned as [width,height]. The
units of measurement are pixels.
Parent Parent container of slider
app window object (default) | panel object | button group object
Parent container of the slider, specified as an app window handle, panel, or button group
object.
Size Size of slider, excluding tick marks and labels
[120,6] (default) | [width,height].
Size of the slider, excluding tick marks and state labels, specified as [width,height].
The units of measurement are pixels.
5-128
Slider Properties
Property Reference
For example, if the slider is on 1.0, and the user single clicks 1.1, the callback
executes and the event value updates once to 1.1.
If an app user clicks and drags the slider to a new value, the callback executes
repeatedly.
For example, if the slider value is 1.0, and the user clicks, holds, and drags to value
1.1, the callback executes and the event Value is updated to 1.1. If the user continues
the drag to 1.2, the callback executes again and the event Value is updated to 1.2.
When the user releases the mouse, the callback does not execute.
If the Slider Value property changes programmatically, then the callback does not
execute.
The number of events sent varies, depending on factors such as the mouse speed, the
operating system, and the screen resolution.
Example: @function
Example: {@function, x}
Visible Slider visibility
true (default) | false
Slider visibility, specified as true or false. The Visible property determines whether
the slider is displayed on the screen. If the Visible property of a slider is set to false, the
entire slider is hidden, but you can still specify and access its properties.
5-130
Property Reference
Result
'left'
'center'
'top'
'bottom'
'right'
Note: The preceding images reflect the icon location when HorizontalAlignment and
VerticalAlignment are each set to their default value, 'center'.
If you specify an empty string ('') for the Text property, the IconAlignment property
has no effect.
Location Location of state button relative to parent container
[100,100] (default) | [x,y]
Location of the state button relative to parent container, specified as [x,y], where x and
y specify the coordinates from the lower-left corner of the parent container to the lowerleft corner of the State Button. The units of measurement are pixels.
5-133
Property Reference
String that is a valid MATLAB expression, which is evaluated in the base workspace.
Example: @function
Example: {@function, x}
VerticalAlignment Vertical alignment of text within state button
'center' (default) | 'top' | 'bottom'
Vertical alignment of text within the state button. specified as 'center', 'top', or
'bottom'.
The following image shows the three vertical alignment options when the
HorizontalAlignment is 'center'. In the image, from top to bottom, the vertical
alignment values are , 'top', 'center', 'bottom'.
Note: Vertical alignment values appear to have the no effect when the button is the
default height.
Visible State Button visibility
true (default) | false
State Button visibility, specified as true or false. The Visible property determines
whether the state button is displayed on the screen. If the Visible property of a state
button is set to false, the entire state button is hidden, but you can still specify and
access its properties.
5-135
Property Reference
Switch Properties
Control switch appearance and behavior
Switches are app components that indicate a logical state. Typically, switches generate
an action when the state changes. Properties control the appearance and behavior of a
particular instance of a switch. To modify aspects of a check box, change property values.
Use dot notation to refer to a particular object and property:
sliderswitch = uiswitch;
val = sliderswitch.Value;
sliderswitch.Value = true;
Switch Properties
Location of switch, inclusive of state labels, relative to parent, returned as [x,y], where
x and y specify the coordinates from the lower-left corner of the parent container to the
lower-left corner of the switch, including state labels. The units of measurement are
pixels.
OuterSize Size of switch, inclusive of state labels
[88,20] (default) | [width height]
Size of switch, inclusive of state labels, returned as [width,height]. The units of
measurement are pixels.
Parent Parent container of switch
app window object (default) | panel object | button group object
Parent container of switch, specified as an app window, panel, or button group object.
Size Size of switch, exclusive of state labels
[45,20] (default) | [width,height]
Size of switch, exclusive of state labels, specified as [width,height]. The units of
measurement are pixels.
Text Switch state labels
{'Off', 'On'} (default) | 1-by2 cell array strings
Switch state labels, specified as a 1-by-2 cell array of strings.
When the switch Orientation property is set to 'vertical', the first element of the
array appears on the bottom of the switch. When the Orientation property is set to
'horizontal', the first element of the array appears to the left of the switch.
Value State of switch
false (default) | true
State of switch, specified as one of the following values:
false
The switch points down when the Orientation property is set to 'vertical' and
points left when the Orientation property is set to 'horizontal'.
true
5-137
Property Reference
The switch points up when the Orientation property is set to 'vertical' and points
right when the Orientation property is set to 'horizontal'.
ValueChangedFcn Code to execute when app user changes switch state
[] (default) | function handle | cell array | string
Code to execute when app user changes switch state, specified as one of these values:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
The app user can change the switch state by clicking and releasing the mouse button
anywhere on the switch (including the state labels), or by clicking on the switch,
dragging, and releasing the mouse button while still on the switch.
Example: @function
Example: {@function, x}
Visible Switch visibility
true (default) | false
Switch visibility, specified as true or false. The Visible property determines whether
the switch is displayed on the screen. If the Visible property of a switch is set to false,
the entire switch is hidden, but you can still specify and access its properties.
5-138
Font Style
Editable Whether text area is editable
true (default) | false
Whether the text area is editable, specified as true or false.
This table summarizes the visual and functional results of various combinations of
property values for the Editable and Enabled properties:
Enabled
Editable
Visual Results
Functional Results
'true'
'true'
'false'
'false'
5-139
Property Reference
Enabled
Editable
Visual Results
Functional Results
'true'
'false'
'false'
'true'
Editable
'true'
'true'
'false'
'false'
'true'
'false'
5-140
Visual Results
Functional Results
Enabled
Editable
'false'
'true'
Visual Results
Functional Results
App user cannot update the
text field.
Property Reference
Alignment of text within the text area, specified as 'left', 'right', or 'center'.
The alignment affects the display as the app user edits the text area and how MATLAB
displays the text in the app.
Location Location of text area relative to parent
[100,100] (default) | [x,y]
Location of text area relative to parent, specified as [x,y], where x and y specify the
coordinates from the lower-left corner of the parent container to the lower-left corner of
the text area. The units of measurement are pixels.
OuterLocation Location of text area relative to parent container
[100,100] (default) | [x,y]
Identical to Location for Text Areas.
OuterSize Size of text area, including Text value
[150,50] (default) | [width,height]
Identical to Size for Text Areas.
Parent Parent container of text area
app window object (default) | panel object | button group object
Parent container of text area, specified as an app window, panel, or button group object.
Size Size of text area
[150,50] (default) | [width,height]
Size of thetext area, specified as [width,height]. The units of measurement are pixels.
Value Text in text area
{''} (default) | cell array of strings
Text in text area, specified as a cell array of strings. MATLAB can properly render
formatted text, such as this:
cellArrayText{1} = sprintf('%s\n%s', 'Line 1', 'Line 2')
cellArrayText{2} = sprintf('%s\n%s', 'Line 3', 'Line 4')
textarea = uitextarea('Value',cellArrayText);
5-142
If a row of text in the cell array does not fit into the width of the Text Area, MATLAB
wraps the text.
If there are too many rows to display in the Text Area size, MATLAB adds a scroll bar.
Example: {'Joseph Welford'; 'Mary Reilly'; 'Roberta Silberlicht'}
ValueChangedFcn Callback to execute after app user commits text entry
[] (default) | function handle | cell array | string
Callback function to execute after app user enters text, specified as a function handle,
a cell array containing a function handle and additional arguments, or a string. The
callback executes after the app user types text in the text area and then either presses
Enter, or clicks outside the text area.
Example: @function
Example: {@function, x}
Visible Text Area visibility
true (default) | false
Text Area visibility, specified as true or false. The Visible property determines
whether the text area is displayed on the screen. If the Visible property of a text area
is set to false, the entire text area is hidden, but you can still specify and access its
properties.
5-143
Property Reference
Note: To specify how you want your app to respond when a user changes a toggle button
selection, code the ValueChangedFcn callback for the Button Group to which the toggle
buttons are parented.
Enabled Operational state of toggle button
true (default) | false
Operational state of toggle button, specified as true or false.
If you set this property to true, the appearance of the toggle button indicates that an
app user can select it.
If you set this property to false, the appearance of the toggle button appears dimmed,
indicating that an app user cannot select it.
FontAngle Character slant of toggle button text
'normal' (default) | 'italic'
Character slant of the toggle button text, specified as 'normal' or 'italic'. Setting
this property to italic selects a slanted version of the font, if it is available on the app
users system.
FontName Font in which to display toggle button text
'Helvetica' (default) | string
5-144
Font in which to display the toggle button Text property value, specified as a string.
If the specified font is not available to the app user, MATLAB uses 'Helvetica'. If
'Helvetica' is not available, MATLAB uses an available sans serif font.
Example: 'Arial'
FontSize Font size of toggle button text
12 (default) | positive number
Font size of toggle button text, specified as a positive number. The units of measurement
are points.
Example: 14
FontWeight Thickness of text characters
'normal' (default) | 'bold'
Thickness of the text characters, specified as one of these values:
'normal' Default weight as defined by the particular font
'bold' Thicker character outlines than 'normal'
Not all fonts have a bold font weight. Therefore, specifying a bold font weight can result
in the normal font weight.
HorizontalAlignment Horizontal alignment of icon and text within toggle button
'center' (default) | 'left' | 'right'
Horizontal alignment of text and icon within the toggle button, specified as 'center',
'left', or 'right'.
The following image shows the three horizontal alignment options, center, left, and right,
when the VerticalAlignment and IconAlignment properties are set to their default values
('center' and 'left', respectively).
Property Reference
Result
'left'
'center'
'top'
'bottom'
'right'
Note: The preceding images reflect the icon location when HorizontalAlignment and
VerticalAlignment are each set to their default value, 'center'.
If you specify an empty string ('') for the Text property, then the icon aligns as though
it is text, according to the values set for HorizontalAlignment and VerticalAlignment.
The IconAlignment property value has no effect in this case.
5-146
Property Reference
When the Value property for a toggle button changes to true, the Value property for the
previously selected toggle button parented to the same button group changes to false.
In addition, the SelectedObject property value of the button group is updated to reflect
the selected toggle button.
If you programmatically change the Value property for a toggle button to false,
MATLAB sets the first toggle button in the button group to true. If the first toggle
button is the one for which you set the Value property for a toggle button to false, then
MATLAB sets the second toggle button in the button group to true.
VerticalAlignment Vertical alignment of text within toggle button
'center' (default) | 'top' | 'bottom'
Vertical alignment of text within the toggle button. specified as 'center', 'top', or
'bottom'.
Note: Vertical alignment values appear to have the no effect when the toggle button is
the default height.
Visible Toggle Button visibility
true (default) | false
Toggle Button visibility, specified as true or false. The Visible property determines
whether the toggle button is displayed on the screen.
5-148
Property Reference
The toggle switch points down when the Orientation property is set to 'vertical'
and points left when the Orientation property is set to 'horizontal'.
true
The toggle switch points up when the Orientation property is set to 'vertical' and
points right when the Orientation property is set to 'horizontal'.
ValueChangedFcn Code to execute when app user changes toggle switch state
[] (default) | function handle | cell array | string
Code to execute when app user changes toggle switch state, specified as one of the
following:
Function handle
Cell array containing a function handle and additional arguments
String that is a valid MATLAB expression, which is evaluated in the base workspace.
The app user can change the toggle switch state by clicking and releasing the mouse
button anywhere on the toggle switch (including the state labels), or by clicking on the
toggle switch, dragging, and releasing the mouse button while still on the toggle switch.
Example: @function
Example: {@function, x}
Visible Toggle Switch visibility
true (default) | false
Toggle Switch visibility, specified as true or false. The Visible property determines
whether the toggle switch is displayed on the screen. If the Visible property of a toggle
switch is set to false, the entire toggle switch is hidden, but you can still specify and
access its properties.
5-151
5-152
6
Function Reference
appdesigner
appwindow
axes
uibutton
uicheckbox
uidropdown
uieditfield
uigauge
uiknob
uilabel
uilamp
uilistbox
uiradiobutton
uislider
uiswitch
uitextarea
uitogglebutton
Function Reference
appdesigner
Create or edit app file in App Designer
Syntax
appdesigner
appdesigner file
Description
appdesigner opens the app building environment, App Designer.
appdesigner file opens the specified app file in App Designer.
appdesigner myappfile
Input Arguments
file Name of app file
string
Name of an app file, specified as a string. If file is overloaded (that is, it appears in
multiple folders on the search path), then include a path to the file. The file specification
must be the complete or relative path to the file, or the name of a file on the MATLAB
path. Otherwise, MATLAB returns an error.
Example: appdesigner App1
Examples
Open a New App File
appdesigner
6-2
appdesigner
A new file titled App1.mlapp opens in App Designer. App1.mlapp does not appear in
the MATLAB Current Folder browser until you save the file.
Open an Existing App File
appdesigner valueplots
App Designer opens and displays the existing valueplots.mlapp file, assuming that
file is in the current folder or on the MATLAB search path. Otherwise, MATLAB returns
a file not found error.
6-3
Function Reference
appwindow
Create app window component
Syntax
appwindow
window = appwindow(Name,Value)
Description
appwindow creates a new app window using default property values.
window = appwindow(Name,Value) specifies app window properties using one or
more Name,Value pair arguments.
Input Arguments
Name-Value Pair Arguments
Specify optional comma-separated pairs of Name,Value arguments. Name is the
argument name and Value is the corresponding value. Name must appear inside single
quotes (' '). You can specify several name and value pair arguments in any order as
Name1,Value1,...,NameN,ValueN.
For a list and description of properties (name-value pair arguments), see App Window
Properties.
Example: 'Name','Results'
Examples
Create Default App Window
appwindow;
6-4
appwindow
6-5
Function Reference
678
560
See Also
Properties
App Window Properties
6-6
420
axes
axes
Create axes graphics object
Syntax
ax = axes('Parent',app)
ax = axes('Parent',app,Name,Value)
Description
ax = axes('Parent',app) creates an axes object within the specified app window.
ax = axes('Parent',app,Name,Value) specifies axes properties using one or more
Name,Value pair arguments.
Input Arguments
app app window
app window object
App window, specified as an app window object.
6-7
Function Reference
Examples
Multiple Axes in Single App Window
Create and plot into multiple axes in a single app window.
Specify the axes object in the plot command to indicate in which axes you want each plot
to be displayed.
window = appwindow;
a = [1,4,7,9];
b = [10,12,30,4];
ax1 = axes('Parent',window,'Units','pixels',...
'Position',[67, 171, 175, 152]);
ax2 = axes('Parent',window,'Units','pixels',...
'Position',[330,167,179,156]);
plot(ax1,a,b);
plot(ax2,b,a);
6-8
axes
More About
Tips
The axis (not axes) function provides simplified access to commonly used properties
that control the scaling and appearance of axes.
6-9
Function Reference
For information on setting default axes properties, see the MATLAB help topic,
Default Property Values.
See Also
Functions
axis | cla | clf | gca | grid | subplot | title | view | xlabel | ylabel
Properties
Axes Properties
6-10
uibutton
uibutton
Create push button or state button component
Syntax
button
button
button
button
button
=
=
=
=
=
uibutton
uibutton(style)
uibutton(parent)
uibutton(parent,style)
uibutton( ___ ,Name,Value)
Description
button = uibutton creates a push button in a new app window.
button = uibutton(style) creates a button of the specified style.
button = uibutton(parent) specifies the object in which to create the button.
button = uibutton(parent,style) creates a button of the specified style in the
specified parent object.
button = uibutton( ___ ,Name,Value) specifies button properties using one or
more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
style Type of button
'push' (default) | 'state'
Type of button, specified as one of the following:
'push'
6-11
Function Reference
Examples
Create a Push Button
Create a push button, the default style for a button.
button = uibutton;
6-12
uibutton
Function Reference
Create two app windows, app1 and app2. Specify app2 as the parent app window for the
button.
window1 = appwindow('Name','One');
window2 = appwindow('Name','Two');
button = uibutton(window2);
6-14
uibutton
6-15
Function Reference
See Also
Properties
Button Properties | State Button Properties
6-16
uicheckbox
uicheckbox
Create check box component
Syntax
checkbox = uicheckbox
checkbox = uicheckbox(parent)
checkbox = uicheckbox( ___ ,Name,Value)
Description
checkbox = uicheckbox creates a check box in a new app window.
checkbox = uicheckbox(parent) specifies the object in which to create the check
box.
checkbox = uicheckbox( ___ ,Name,Value) specifies check box properties using one
or more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
parent Check box parent container
app window object (default) | panel object | button group object
Check box parent container, specified as an app window, panel, or button group object.
Function Reference
For a list and description of properties (name-value pair arguments), see Check Box
Properties.
Example: 'Value',true specifies that the check box is displayed with a check mark.
Examples
Create Check Box
checkbox = uicheckbox;
uicheckbox
Function Reference
box, the third button in the button group is disabled. When the user clears the check box,
the radio button is enabled again.
Save the following code to a file on your MATLAB path.
function disableRadioButton
% Create an app window:
window = appwindow('Position',[100, 100, 229, 276]);
% Create a checkbox:
uicheckbox(window,'Location',[55, 217],...
'ValueChangedFcn',@(checkbox,event) cBoxChanged(checkbox,rb3));
end
% Create the function for the ValueChangedFcn callback:
function cBoxChanged(checkbox,rb3)
val = checkbox.Value;
rb3.Enabled = ~val;
end
6-20
uicheckbox
See Also
Properties
Check Box Properties
6-21
Function Reference
uidropdown
Create drop down component
Syntax
dropdown
dropdown
dropdown
dropdown
dropdown
=
=
=
=
=
uidropdown
uidropdown(style)
uidropdown(parent)
uidropdown(parent,style)
uidropdown( ___ ,Name,Value)
Description
dropdown = uidropdown creates a drop down in a new app window.
dropdown = uidropdown(style) creates a drop down of the specified style.
dropdown = uidropdown(parent) specifies the object in which to create the drop
down.
dropdown = uidropdown(parent,style) creates a drop down of the specified style
in the specified parent object.
dropdown = uidropdown( ___ ,Name,Value) specifies drop down properties
using one or more Name,Value pair arguments. Use this option with any of the input
argument combinations in the previous syntaxes.
Input Arguments
style Type of drop down
'dropdown' (default) | 'editable'
Type of drop down, specified as one of the following:
'dropdown'
6-22
uidropdown
Examples
Create a Drop Down
dropdown = uidropdown;
6-23
Function Reference
6-24
uidropdown
6-25
Function Reference
Make the font of the text that is displayed in the drop down italic:
dropdown.FontAngle = 'italic';
6-26
uidropdown
Run plotOptions. Select an option from the drop down to change the plot color.
6-27
Function Reference
Code the Editable Drop Down ValueChangedFcn Callback Using Value and Data Properties
Create an app window containing an editable drop down and a lamp. Code the callback
for the drop down such that when the user selects an option or types a numeric value in
the drop down, the size of the lamp is multiplied by that value. This example illustrates
how to use the Text and Value properties to determine the app user selection.
Save the following code to a file on your MATLAB path.
function lampSize
% Create app window and components
window = appwindow('Position',[100, 100, 300, 275]);
lamp = uilamp(window,...
'Location',[100, 25]);
dropdown = uidropdown(window,'editable',...
'Location',[84,204],...
'Text',{'1','2','3','4'},...
'Value','1',...
6-28
uidropdown
'ValueChangedFcn',@(dropdown,event) optionSelected(dropdown,lamp));
end
% Create ValueChangedFcn callback
function optionSelected(dropdown,lamp)
val = dropdown.Value;
s = [20 20];
switch val
case 'Option 1'
lamp.Size = s;
case 'Option 2'
lamp.Size = s.*[2, 2];
case 'Option 3'
lamp.Size = s.*[3, 3];
case 'Option 4'
lamp.Size = s.*[4, 4];
otherwise
v = dropdown.Value;
m = str2num(v);
lamp.Size = s.*[m, m];
end
end
Run lampSize and select various options from the drop down.
Enter a value in the drop down. (If you enter a large value, you might have to resize the
app window to see the lamp.)
6-29
Function Reference
Code the Editable Drop Down ValueChangedFcn Callback Using ValueData and TextData
Properties
Create an app window containing an editable drop down and a lamp. Code the callback
for the drop down such that when the user selects an option the lamp size changes to
a size appropriate for the selection. When the user types a numeric value in the drop
down, the lamp dimension become that value. This example illustrates how to use the
ValueData and TextData properties to determine the app user selection.
Save the following code to a file on your MATLAB path.
function lampSizer
% Create app window and components
window = appwindow('Position',[100, 100, 300, 275]);
lamp = uilamp(window,...
'Location',[100, 25]);
dropdown = uidropdown(window,'editable',...
'Location',[84,204],...
6-30
uidropdown
'Text',{'small','medium','large','extra large'},...
'Value','medium',...
'TextData',{10,20,30,40},...
'ValueChangedFcn',@(dropdown,event) optionSelected(dropdown,lamp));
end
% Create ValueChangedFcn callback
function optionSelected(dropdown,lamp)
val = dropdown.ValueData;
if (~isempty(val))
% User selected option
lamp.Size = val * [1,1];
else
% User typed a value
v = dropdown.Value;
n = str2num(v);
if (~isempty(n))
% User typed a number
lamp.Size = n *[1,1];
else
% If user did not type a number,
% use the default lamp size
lamp.Size = [20,20];
end
end
end
Run lampSizer and select various options from the drop down.
Enter a numeric value in the drop down. (If you enter a large value, you may need to
resize the app window to see the lamp.)
6-31
Function Reference
See Also
Properties
Drop Down Properties | Editable Drop Down Properties
6-32
uieditfield
uieditfield
Create text or numeric edit field component
Syntax
editfield
editfield
editfield
editfield
editfield
=
=
=
=
=
uieditfield
uieditfield(style)
uieditfield(parent)
uieditfield(parent,style)
uieditfield( ___ ,Name,Value)
Description
editfield = uieditfield creates a text edit field in a new app window.
editfield = uieditfield(style) creates an edit field of the specified style.
editfield = uieditfield(parent) specifies the object in which to create the edit
field.
editfield = uieditfield(parent,style) creates an edit field of the specified style
in the specified parent object.
editfield = uieditfield( ___ ,Name,Value) specifies edit field properties
using one or more Name,Value pair arguments. Use this option with any of the input
argument combinations in the previous syntaxes.
Input Arguments
style Type of edit field
'text' (default) | 'numeric'
Type of edit field, specified as one of the following:
'text'
6-33
Function Reference
Examples
Create a Text Edit Field
Create a text edit field, the default style for an edit field.
editfield = uieditfield;
6-34
uieditfield
6-35
Function Reference
Inf
uieditfield
Run the command. If you enter a value in the numeric edit field that is outside the limits,
MATLAB automatically displays a message indicating the problem and restores the
value to the previous valid value.
Create a Numeric Edit Field That Displays Values Using Exactly Two Decimals
Create a numeric edit field that allows users to enter any value, but always displays the
value using exactly two decimals. Be aware than MATLAB stores the exact value that
the user enters.
editfield = uieditfield('numeric',...
'ValueDisplayFormat', '%.2f');
Enter 5.555 in the numeric edit field, and then click away from the edit field. The edit
field displays 5.55.
MATLAB stores the original value, 5.555.
Click in the edit field, it displays the value originally typed.
Code the ValueChangedFcn Callback for a Text Edit Field
Code the ValueChangedFcn callback for a text edit field such that when the user
changes text in the edit field, the label is updated to match that text.
Save the following code to a file on your MATLAB path.
function textValue
% Create app window and components
6-37
Function Reference
window = appwindow('Position',[100,100,350,275]);
label = uilabel(window,...
'Location',[130, 100],...
'Size',[100,20]);
textfield = uieditfield(window,...
'Location',[100,175],...
'ValueChangedFcn',@(textfield,event) textChanged(textfield,label));
end
function textChanged(textfield,label)
label.Text = textfield.Value;
end
Run textValue, and type Velocity in the edit field. Click outside the edit field to
trigger the callback.
uieditfield
Run numericEditFieldValue.
Enter a value between 0 and 100 in the numeric edit field and click outside the field. The
slider moves to indicate the numeric edit field value.
6-39
Function Reference
See Also
Functions
uitextarea
Properties
Edit Field Properties | Numeric Edit Field Properties
6-40
uigauge
uigauge
Create circular, linear, ninety-degree, or semicircular gauge component
Syntax
gauge
gauge
gauge
gauge
gauge
=
=
=
=
=
uigauge
uigauge(style)
uigauge(parent)
uigauge(parent,style)
uigauge( ___ ,Name,Value)
Description
gauge = uigauge creates a circular gauge in a new app window.
gauge = uigauge(style) specifies the gauge style.
gauge = uigauge(parent) specifies the object in which to create the gauge.
gauge = uigauge(parent,style) creates a gauge of the specified style in the
specified parent object.
gauge = uigauge( ___ ,Name,Value) specifies gauge properties using one or
more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
style Type of gauge
'circular' (default) | 'linear' | 'ninetydegree' | 'semicircular'
Type of gauge, specified as any one of the following values:
6-41
Function Reference
Style
Default Visual
Description
'circular'
'linear'
'ninetydegree'
'semicircular'
6-42
uigauge
Examples
Create a Circular Gauge
gauge = uigauge;
6-43
Function Reference
Change gauge major ticks, specify matching tick labels, and remove minor ticks.
gauge.MajorTicks = [0:10:100];
gauge.MajorTickLabels = {'0','10','20','30','40','50','60','70','80','90','100'};
gauge.MinorTicks = [];
6-44
uigauge
size =
120
120
Create a Circular Gauge, Specifying Scale Colors and Scale Color Limits
gauge = uigauge('ScaleColors', {'yellow', 'red'},...
'ScaleColorLimits', [60,80; 80,100]);
6-45
Function Reference
See Also
Properties
Gauge Properties | Linear Gauge Properties | Ninety-Degree Gauge Properties |
Semicircular Gauge Properties
6-46
uiknob
uiknob
Create knob or discrete knob app component
Syntax
knob
knob
knob
knob
knob
=
=
=
=
=
uiknob
uiknob(style)
uiknob(parent)
uiknob(parent,style)
uiknob( ___ ,Name,Value)
Description
knob = uiknob creates a knob in a new app window.
knob = uiknob(style) specifies the knob style.
knob = uiknob(parent) specifies the object in which to create the knob.
knob = uiknob(parent,style) creates a knob of the specified style in the specified
parent object.
knob = uiknob( ___ ,Name,Value) specifies knob properties using one or more
Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
style Type of knob
'continuous' (default) | 'discrete'
Type of knob, specified as one of the following values:
6-47
Function Reference
Style
Default Visual
'continuous'
'discrete'
Examples
Create a Default Knob
Create a continuous knob, the default knob style.
6-48
uiknob
knob = uiknob;
6-49
Function Reference
100
uiknob
knob.Limits = [-10,10];
knob.Value = 5;
Change the knob states. Set the data associated with the knob states to reflect
temperatures in degrees Fahrenheit.
knob.Text = {'Cold', 'Warm', 'Hot'};
knob.TextData = {32, 80, 212};
6-51
Function Reference
Get the data value (temperature) associated with the current knob value.
degrees = knob.ValueData
degrees =
32
6-52
uiknob
Run displayKnobValue, and then turn the knob. When you release the mouse button,
the edit field is updated to reflect the knob value.
6-53
Function Reference
label = uilabel(window,'Location',[218,177],...
'Text','0',...
'Size', [50,15]);
knob = uiknob(window,...
'Location',[89, 142],...
'ValueChangedFcn', @(knob,event) knobTurned(knob,label));
end
% Create ValueChangedFcn callback
function knobTurned(knob,label)
num = knob.Value;
label.Text = num2str(num);
end
Run showKnobValue and turn the knob. When you release the mouse button, the label is
updated to reflect the knob value.
uiknob
the edit field is continuously updated to reflect the knob value. MATLAB stores the
changing knob value in the callback event data.
Copy and paste the following code into a file named showchangingvalue.m on your
MATLAB path.
function showChangingValue
% Create app window and components
window = appwindow('Position',[100, 100, 350, 275]);
numberfield = uieditfield(window,'numeric',...
'Location',[218,160]);
knob = uiknob(window,...
'Location',[89, 142],...
'ValueChangingFcn',@(knob,event) knobTurned(knob,event,numberfield));
end
% Create ValueChangingFcn callback
function knobTurned(knob,event,numberfield)
numberfield.Value = event.Value;
end
Run showChangingValue, and turn the knob. As you do so, the numeric edit field is
updated to show the changing knob values.
6-55
Function Reference
See Also
Properties
Discrete Knob Properties | Knob Properties
6-56
uilabel
uilabel
Create label component
Syntax
label = uilabel
label = uilabel(parent)
label = uilabel( ___ ,Name,Value)
Description
label = uilabel creates a component label with the text Label.
label = uilabel(parent) specifies the object in which to create the label.
label = uilabel( ___ ,Name,Value) specifies label properties using one or
more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
parent Label parent container
app window object (default) | panel object | button group object
Label parent container, specified as an app window, panel, or button group object.
Function Reference
However, MATLAB does not automatically interpret and render text such as this:
label = uilabel('Text', 'Line 1\nLine2', 'Size',[100,150])
Example: 'Threshold'
Example: {'Threshold' 'Value'}
Examples
Create a Label Component
label = uilabel;
6-58
uilabel
6-59
Function Reference
The label is clipped because the current size is not large enough for the changed text.
Determine the current label size.
size = label.Size
6-60
uilabel
size =
31
15
See Also
Properties
Label Properties
6-61
Function Reference
uilamp
Create lamp component
Syntax
lamp = uilamp
lamp = uilamp(parent)
lamp = uilamp( ___ ,Name,Value)
Description
lamp = uilamp creates a lamp component in a new app window.
lamp = uilamp(parent) specifies the object in which to create the lamp.
lamp = uilamp( ___ ,Name,Value) specifies lamp properties using one or more
Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
parent Lamp parent container
app window object (default) | panel object | button group object
Lamp parent container, specified as an app window, panel, or button group object.
uilamp
Examples
Create a Lamp Component
Create a green lamp component.
lamp = uilamp;
6-63
Function Reference
6-64
uilamp
See Also
Properties
Lamp Properties
6-65
Function Reference
uilistbox
Create list box component
Syntax
listbox = uilistbox
listbox = uilistbox(parent)
listbox = uilistbox( ___ ,Name,Value)
Description
listbox = uilistbox creates a list box in a new app window.
listbox = uilistbox(parent) specifies the object in which to create the list box.
listbox = uilistbox( ___ ,Name,Value) specifies list box properties using one
or more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
parent List box parent container
app window object (default) | panel object | button group object
List box parent container, specified as an app window, panel, or button group object.
uilistbox
Example: 'Text',{'Model 1','Model 2', 'Model 3', 'Model 4'} specifies the
list box options that the user sees, from top to bottom.
Examples
Create a List Box
listbox = uilistbox;
Function Reference
listbox = uilistbox;
Run listBoxSelection and select an option from the list. The text edit field is updated
to reflect your choice.
6-68
uilistbox
Code the ValueChangedFcn Callback for a List Box to Display Data Associated with Selection
Create an app window containing a list box and a numeric edit field. Code the callback
for the list box so that when a user selects a list option, MATLAB displays the data
associated with that option in the numeric edit field.
Save the following code to a file on your MATLAB path.
function dataSelection
% Create app window and components
window = appwindow('Position',[100,100,350,275]);
numericfield = uieditfield(window,'numeric',...
'Location',[86,90]);
lbox = uilistbox(window,...
'Text', {'Freezing', 'Warm', 'Hot', 'Boiling'},...
'TextData', {0, 25, 40, 100},...
'Location',[100, 120],...
6-69
Function Reference
Run dataSelection and select an option from the list. The numeric edit field is
updated to reflect the data associated with your choice.
6-70
uilistbox
Run multiselect and select options from the list. The text edit field is updated to
reflect your choice.
6-71
Function Reference
See Also
Properties
List Box Properties
6-72
uiradiobutton
uiradiobutton
Create radio button component
Syntax
radiobutton = uiradiobutton(parent)
radiobutton = uiradiobutton(parent,Name,Value)
Description
radiobutton = uiradiobutton(parent) creates a radio button within the specified
parent button group.
radiobutton = uiradiobutton(parent,Name,Value) specifies radio button
properties using one or more Name,Value pair arguments.
Input Arguments
parent Radio button parent container
matlab.ui.control.ButtonGroup object
Radio button parent container, specified as a matlab.ui.control.ButtonGroup
object.
Function Reference
Examples
Create Radio Buttons Within a Button Group and Access Property Values
To create a radio button, first create an app window and a button group object.
window = appwindow;
bg = matlab.ui.control.ButtonGroup('Parent',window);
6-74
uiradiobutton
6-75
Function Reference
See Also
uitogglebutton
6-76
uislider
uislider
Create slider component
Syntax
slider = uislider
slider = uislider(parent)
slider = uislider( ___ ,Name,Value)
Description
slider = uislider creates a slider in a new app window.
slider = uislider(parent) specifies the object in which to create the slider.
slider = uislider( ___ ,Name,Value) specifies slider properties using one or
more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
parent Slider parent container
app window object (default) | panel object | button group object
Slider parent container, specified as an app window, panel, or button group object.
Function Reference
Examples
Create a Slider
slider = uislider;
6-78
uislider
100
6-79
Function Reference
'ValueChangedFcn',@(slider,event) sliderMoved(slider,gauge));
end
% Create ValueChangedFcn callback
function sliderMoved(slider,gauge)
gauge.Value = slider.Value;
end
Run sliderValue, and then move the slider. When you release the mouse button, the
circular gauge needle moves to the matching value on the gauge.
6-80
uislider
gauge = uigauge(window,'Location',[100,100]);
slider = uislider(window,...
'Location',[100, 75],...
'ValueChangingFcn',@(slider,event) sliderMoving(event,gauge));
end
% Create ValueChangingFcn callback
function sliderMoving(event,gauge)
gauge.Value = event.Value;
end
Run sliderChanging, and then move the slider. As you move the slider, the circular
gauge needle moves, reflecting the slider value.
See Also
Properties
Slider Properties
6-81
Function Reference
uiswitch
Create slider switch, rocker switch, or toggle switch component
Syntax
control
control
control
control
control
=
=
=
=
=
uiswitch
uiswitch(style)
uiswitch(parent)
uiswitch(parent,style)
uiswitch( ___ ,Name,Value)
Description
control = uiswitch creates a slider switch component in a new app window.
control = uiswitch(style) creates a switch of the specified style.
control = uiswitch(parent) specifies the object in which to create the switch.
control = uiswitch(parent,style) creates a switch of the specified style in the
specified parent object.
control = uiswitch( ___ ,Name,Value) specifies switch properties using one or
more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
style Type of switch
'slider' (default) | 'rocker' | 'toggle'
Type of switch, specified as one of the following styles:
Style
'slider'
6-82
Default Visual
uiswitch
Style
Default Visual
'rocker'
'toggle'
Examples
Create a Slider Switch
Create a slider switch, the default style for a switch.
sliderswitch = uiswitch;
6-83
Function Reference
6-84
uiswitch
'
6-85
Function Reference
MATLAB returns zero, indicating that the switch points downward to the Stop position.
(If you change the Orientation property value to 'horizontal', the switch points to the
left when the Value property is zero.)
Code the ValueChangedFcn Callback for a Rocker Switch
Create an app window containing a lamp and a rocker switch. Code the callback for the
rocker switch so that when a user presses moves the switch, the lamp changes color.
Save the following code to a file on your MATLAB path.
function lampSwitch
% Create app window and components
window = appwindow('Position',[100,100,350,275]);
lamp = uilamp(window,...
'Location',[150,75]);
rockerswitch = uiswitch(window,'toggle',...
'Location',[150, 160],...
'Value', true,...
'ValueChangedFcn',@(rockerswitch,event) switchMoved(rockerswitch,lamp));
end
% Create ValueChangedFcn callback
function switchMoved(rockerswitch,lamp)
switch rockerswitch.Value
case 1
lamp.Color = 'green';
case 0
lamp.Color = 'black';
end
end
6-86
uiswitch
See Also
Properties
Rocker Switch Properties | Switch Properties | Toggle Switch Properties
6-87
Function Reference
uitextarea
Create text area component
Syntax
textarea = uitextarea
textarea = uitextarea(parent)
textarea = uitextarea( ___ ,Name,Value)
Description
textarea = uitextarea creates a text area in a new app window.
textarea = uitextarea(parent) specifies the object in which to create the text area.
textarea = uitextarea( ___ ,Name,Value) specifies text area properties using one
or more Name,Value pair arguments. Use this option with any of the input argument
combinations in the previous syntaxes.
Input Arguments
parent Text area parent container
app window object (default) | panel object | button group object
Text area parent container, specified as an app window, panel, or button group object.
uitextarea
Examples
Create Text Area
textarea = uitextarea;
6-89
Function Reference
Notice that the default size of the text area is not large enough to display all the specified
text.
Determine the current size of the text area.
size = textareafield.Size
size =
150
50
6-90
uitextarea
6-91
Function Reference
textarea = uitextarea(window,...
'Location', [100,100],...
'ValueChangedFcn',@(textarea,event) textEntered(textarea, label2));
% Create ValueChangedFcn callback
function textEntered(textarea,label2)
val = textarea.Value;
label2.Text = '';
% Check each element of text area cell array for text
for k = 1:length(val)
if(~isempty(val{k}))
label2.Text = 'Thank you for your comments!';
break;
end
end
end
end
Run comments, and type text in the text area field. Click away from the text area to
trigger the callback.
6-92
uitextarea
See Also
Functions
uieditfield
Properties
Text Area Properties
6-93
Function Reference
uitogglebutton
Create toggle button component
Syntax
togglebutton = uitogglebutton(parent)
togglebutton = uitogglebutton(parent,Name,Value)
Description
togglebutton = uitogglebutton(parent) creates a toggle button within the
specified parent button group.
togglebutton = uitogglebutton(parent,Name,Value) specifies toggle button
properties using one or more Name,Value pair arguments.
Input Arguments
parent Toggle button parent container
app window object (default) | panel object | button group object
Toggle button parent container, specified as an app window, panel, or button group
object.
uitogglebutton
Examples
Create Toggle Buttons Within a Button Group and Access Property Values
To create a toggle button, first create an app window and a button group object.
window = appwindow;
bg = matlab.ui.control.ButtonGroup('Parent',window);
6-95
Function Reference
6-96
uitogglebutton
See Also
uiradiobutton
6-97
6-98