Main Content

Specify Labels in States and Transitions Programmatically

When using the Stateflow® API, specify the labels of states and transitions by assigning a character vector to the LabelString property.

To extract parts of the state or transition label, use the properties of the Stateflow.State and Stateflow.Transition objects listed in this table.

API ObjectPropertyTypeDescription
Stateflow.StateDuringActionCharacter vectorText in the during action in this state. This property is not supported in Moore charts.
EntryActionCharacter vectorText in the entry action in this state. This property is not supported in Moore charts.
ExitActionCharacter vectorText in the exit action in this state. This property is not supported in Moore charts.
MooreActionCharacter vectorText in the action in this state. This property is supported only in Moore charts. For more information, see Design Rules for Moore Charts.
NameCharacter vectorName of this state.
OnActionCell array of character vectors

Text in the on actions in this state, parsed as a cell array of this form:


This property is not supported in Moore charts.

Stateflow.TransitionConditionCharacter vectorText in the condition on this transition.
ConditionActionCharacter vectorText in the condition action on this transition.
TransitionActionCharacter vectorText in the transition action on this transition.
TriggerCharacter vectorText in the trigger on this transition.

With the exception of Name, all of these properties are read-only. For more information on the syntax for state and transition labels, see State Labels and Transition Labels.

Enter Labels on Transitions

Suppose that tr is a handle to a transition. You can assign a label that specifies a trigger, condition, and condition action on this transition by entering:

tr.LabelString = 'trigger[guard]{action();}';

Transition with a trigger, a condition, and a condition action.

To extract the trigger, condition, and condition action specified by the transition label, enter:

trigger = tr.Trigger
trigger =

cond = tr.Condition
cond =

action = tr.ConditionAction
action =


Enter Multiline Labels in States

There are two equivalent ways to enter multiline labels for states and transitions. For example, Suppose that sA is a handle to a state. To enter a multiline label with entry and during actions, you can:

  • Call the MATLAB® function sprintf and use the escape sequence \n to insert newline characters:

    str = sprintf('A\nen: action1();\ndu: action2();\nen,du: action3();');
    sA.LabelString = str;
  • Enter a concatenated text expression that uses the integer 10 as the ASCII equivalent of a newline character:

    str = ['A',10, ...
        'en: action1();',10, ...
        'du: action2();',10, ...
        'en,du: action3();'];
    sA.LabelString = str;

State with entry and during actions.

To extract the state name, entry action, and during action specified by the state label, enter:

name = sA.Name
name =

entry = sA.EntryAction
entry =

    ' action1();
during = sA.DuringAction
during =

    ' action2();

See Also

Related Topics