This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Text of a text object

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Value Summary

MandatoryString or function

Graphics Primitives

ObjectsText Default Values
plot::Text2d, plot::Text3d 


The attribute Text represents the text of a text object. It may be a text string or a function generating a text string at runtime.

The Text attribute represents the text in text objects of type plot::Text2d and plot::Text3d. When creating a text object such as

t := plot::Text2d("hello world", [0, 0]),

the text is the first argument. Internally, it is stored as the attribute Text = "hello world" and can be accessed and changed via a slot call t::Text.

In most cases, the text is given as a string.


Note that this string has to be quoted when changing it in the “property inspector” of the interactive graphics tool (see section Viewer, Browser, and Inspector: Interactive Manipulation of this document). If the string contains white space and the quotes are removed, the recalculation following the change will produce a syntax error!

A text given by a fixed string cannot be animated. Use a procedure to create animated texts.

The attribute Text can be a procedure that is called at runtime with the animation parameter as the only input parameter. The return value is used as the text of the text object in the corresponding frame of the animation. If the result is not a string, expr2text is applied to the return value.


Example 1

Usually, a text is given by a string:

t := plot::Text2d("hello world", [1, 1], TextFont = [24]):

We access and change the text:


t::Text := "HELLO WORLD":

The same message in 3D:

plot(plot::Text3d("HELLO WORLD", [1, 1, 1],
                  TextFont = [24]))

delete t:

Example 2

The text of a text object can be animated if the text string is provided by a procedure. We use stringlib::formatf to format the animation parameter that is passed to the procedure as a floating-point number for each frame of the animation:

plot(plot::Rectangle(-1..1, -1..1),
     plot::Text2d(a -> stringlib::formatf(a, 2, 5)." sec",
                  [0, 0], a = 0..20,
                  TextFont = [60], 
                  HorizontalAlignment = Center, 
                  VerticalAlignment = Center),
     Axes = Frame, Frames = 201, TimeRange = 0..20)

Here is the corresponding example in 3D:

plot(plot::Text3d(a -> stringlib::formatf(a, 2, 5)." sec",
                  [0, 0, 0], a = 0..20,
                  TextFont = [60], 
                  HorizontalAlignment = Center, 
                  VerticalAlignment = Center),
     Axes = Frame, Frames = 201, TimeRange = 0..20)

Was this topic helpful?