uilabel
Create label component
Description
creates a label component
(with the text lbl
= uilabel'Label'
) in a new figure window and returns the
Label
object. MATLAB® calls the uifigure
function to create the
figure.
specifies label properties using one or more lbl
= uilabel(___,Name,Value
)Name,Value
pair
arguments. Use this option with any of the input argument combinations in the
previous syntaxes.
Examples
Create Label Component with Default Text
fig = uifigure; lbl = uilabel(fig);
Create Label Component in Panel
Specify a Panel
as the
parent.
fig = uifigure; pnl = uipanel(fig); lbl = uilabel(pnl);
Set and Access Label Component Properties
Create a default label.
fig = uifigure; lbl = uilabel(fig);
Change the label text and font size.
lbl.Text = "Result";
lbl.FontSize = 14;
The label is clipped because the current label size is too small for the new text at the new font size.
Determine the current label size by getting the third and fourth elements
of the Position
property value.
size = lbl.Position(3:4)
size = 31 15
Change the label size to accommodate the new text.
lbl.Position(3:4) = [62 22];
Wrap Long Label Text
Wrap label text to fit within the width of a label.
Create a label. Specify the label text and size.
fig = uifigure;
lbl = uilabel(fig);
lbl.Text = "The data shown represents 18 months of observations.";
lbl.Position = [100 100 100 60];
Wrap the text in the label.
lbl.WordWrap = "on";
Format Label Text
Use HTML markup to selectively format parts of the label text.
Create a label and specify the label size.
fig = uifigure;
lbl = uilabel(fig,"Position",[100 100 150 32]);
Specify the label text using HTML markup and set the label to interpret the text as HTML.
lbl.Text = "<font style='color:green;'>This table</font> is <em>not complete</em>." lbl.Interpreter = "html";
Display Equation
Use LaTeX to display a formatted equation.
Create a label and specify the label size.
fig = uifigure;
lbl = uilabel(fig,"Position",[100 100 125 50]);
Specify the label text and set the label to interpret the text as LaTeX.
lbl.Text = "$$\frac{d}{dx} \int_a^x f(t)\;dt = f(x)$$" lbl.Interpreter = "latex";
Input Arguments
parent
— Parent container
Figure
object (default) | Tab
object | Panel
object | ButtonGroup
object | GridLayout
object
Parent container, specified as a Figure
object created using the uifigure
function or one of its child
containers: Tab
, Panel
, ButtonGroup
, or GridLayout
. If you do not specify a parent container, MATLAB calls the uifigure
function to create a new Figure
object that serves as the parent container.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: uilabel("Text","Sum:")
specifies the label displays the
text Sum:
.
Note
The properties listed here are a subset of the available properties. For the
full list, see Label
.
Text
— Label text
'Label'
(default) | character vector | cell array of character vectors | string scalar | string array | ...
Label text, specified as a character vector, cell array of character vectors, string scalar, string array, or 1-D categorical array. Use a cell array of character vectors or a string array to specify multiple lines of text.
Alternatively, use the sprintf
function
to create formatted text containing line breaks and other special
characters.
text = sprintf('%s\n%s','Line 1','Line 2'); label = uilabel('Text',text,'Position',[100 100 100 32]);
If you specify text as a character vector without using sprintf
,
MATLAB will not interpret control sequences such as \n
.
If you specify this property as a categorical array, MATLAB uses the values in the array, not the full set of categories.
Example: 'Threshold'
Example: {'Threshold' 'Value'}
WordWrap
— Word wrapping to fit component width
'off'
(default) | on/off logical value
Word wrapping to fit component width, specified as 'off'
or 'on'
, or as numeric or logical 0
(false
) or 1
(true
). A value of 'off'
is equivalent to false
, and 'on'
is equivalent to true
. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
Use this property to prevent text from getting clipped horizontally when the width of the component is smaller than the text you want to display.
'off'
— Text does not wrap.'on'
— Breaks text into new lines so that each line fits within the width of the component and avoids breaking words when possible.
Setting the WordWrap
property to 'on'
does not
prevent text from getting clipped vertically when the height of the component is too
small to display all the lines of text.
Position
— Label location and size
[100 100 31 22]
(default) | [left bottom width height]
Label location and size, relative to the parent, specified as the vector [left bottom
width height]
. This table describes each element in the
vector.
Element | Description |
---|---|
left | Distance from the inner left edge of the parent container to the outer left edge of the label |
bottom | Distance from the inner bottom edge of the parent container to the outer bottom edge of the label |
width | Distance between the right and left outer edges of the label |
height | Distance between the top and bottom outer edges of the label |
The Position
values are relative to the
drawable area of the parent container. The drawable area is the area
inside the borders of the container and does not include the area occupied by decorations such
as a menu bar or title.
All measurements are in pixel units.
Example: [100 100 100 20]
Version History
Introduced in R2016aR2021a: Style text and display equations
Use the Interpreter
property to enable HTML or LaTeX markup
for the label text.
For more information, see Label
.
R2020b: Wrap label text
Use the WordWrap
property to prevent text from getting
clipped horizontally when the width of the UI component is smaller than the text you
want to display. Setting the WordWrap
property to
'on'
breaks the text into new lines so that each line fits
within the component. It avoids breaking words when possible. When the property is
set to 'off'
, the text does not wrap.
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)