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 Object | Property | Description |
|---|---|---|
Stateflow.State | DuringAction | Text in the during action in this state. This
property is not supported in Moore charts. |
EntryAction | Text in the entry action in this state. This
property is not supported in Moore charts. | |
ExitAction | Text in the exit action in this state. This
property is not supported in Moore charts. | |
MooreAction | Text in the action in this state. This property is supported only in Moore charts. For more information, see Design Guidelines for Moore Charts. | |
Name | Name of this state. | |
OnAction | Text in the {'trigger1','action1',...,'triggerN','actionN'}This property is not supported in Moore charts. | |
Stateflow.Transition | Condition | Text in the condition on this transition. |
ConditionAction | Text in the condition action on this transition. | |
TransitionAction | Text in the transition action on this transition. | |
Trigger | Text 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 Define Actions in a State and Define Actions in a Transition.
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();}";
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
sprintfand use the escape sequence\nto insert newline characters:str = sprintf("A\nen: action1();\ndu: action2();\nen,du: action3();"); sA.LabelString = str;Enter a concatenated text expression that uses the function
newlineto create newline characters:str = "A" + newline + ... "en: action1();" + newline + ... "du: action2();" + newline + ... "en,du: action3();" sA.LabelString = str;

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();'