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 | Type | Description |
---|---|---|---|
Stateflow.State | DuringAction | Character vector | Text in the during action in this state. This
property is not supported in Moore charts. |
EntryAction | Character vector | Text in the entry action in this state. This
property is not supported in Moore charts. | |
ExitAction | Character vector | Text in the exit action in this state. This
property is not supported in Moore charts. | |
MooreAction | Character vector | Text in the action in this state. This property is supported only in Moore charts. For more information, see Design Rules for Moore Charts. | |
Name | Character vector | Name of this state. | |
OnAction | Cell array of character vectors | Text in the {'trigger1','action1',...,'triggerN','actionN'} This property is not supported in Moore charts. | |
Stateflow.Transition | Condition | Character vector | Text in the condition on this transition. |
ConditionAction | Character vector | Text in the condition action on this transition. | |
TransitionAction | Character vector | Text in the transition action on this transition. | |
Trigger | Character vector | 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 State Labels and Transition Labels.
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();}';
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();'
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;
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();'