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 ObjectPropertyDescription
Stateflow.StateDuringActionText in the during action in this state. This property is not supported in Moore charts.
EntryActionText in the entry action in this state. This property is not supported in Moore charts.
ExitActionText in the exit action in this state. This property is not supported in Moore charts.
MooreActionText in the action in this state. This property is supported only in Moore charts. For more information, see Design Rules for Moore Charts.
NameName of this state.
OnAction

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

{'trigger1','action1',...,'triggerN','actionN'}

This property is not supported in Moore charts.

Stateflow.TransitionConditionText in the condition on this transition.
ConditionActionText in the condition action on this transition.
TransitionActionText in the transition action on this transition.
TriggerText 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 the Stateflow.Transition object that corresponds 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 =

    'trigger'
cond = tr.Condition
cond =

    'guard'
action = tr.ConditionAction
action =

    '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 Stateflow.State object that corresponds 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 =

    'A'
entry = sA.EntryAction
entry =

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

    ' action2();
      action3();'

See Also

Functions

Objects

Related Topics