Stateflow | ![]() ![]() |
State Label Notation
The label for a state appears on the top left corner of the state rectangle with the following general format:
A state label starts with the name of the state followed by an optional / character (see State Name) and additional lines with keyword prefixes. Each keyword prefix identifies a different type of action associated with the state. These actions are as follows (short form is shown in bold):
Prefix |
Action Type |
en try |
Entry action. See Entry Action. |
du ring |
During action. See During Action. |
ex it |
Exit action. See Exit Action. |
on event_nam e |
Action occurring with event event_nam e. See On Event_Name Action. |
You enter action statements for the state after the keyword label that identifies its type of action. Separate multiple actions for each action type with one of the following characters:
You can specify multiple on
event_name
actions for different events by adding multiple on
event_name
lines specifying unique values for event_name
.
Each keyword is optional and positionally independent. You can specify none, some, or all of them. The colon after each keyword is required. The slash following the state name is optional as long as it is followed by a carriage return.
If you enter the name and slash followed directly by actions, the actions are interpreted as entry
action(s). This shorthand is useful if you are only specifying entry
actions.
The action you specify in state labels forms a part of Stateflow action language. See Action Language.
State Label Example
The following example demonstrates the components of a state label.
State Name. In this example, the state names are On
and Off
. The name of the state forms the first part of the state label. Valid state names consist of alphanumeric characters and can include the underscore (_
) character, for example, Transmission
or Green_on
.
The use of hierarchy provides some flexibility in the naming of states. The name that you enter as part of the label must be unique when preceded by the hierarchy of its ancestor states. The name stored in the data dictionary is the text you enter as the label on the state, preceded by the hierarchy of its parent states separated by periods. Each state can have the same name appear in the label of the state, as long as their full names within the data dictionary are unique. Otherwise, the parser indicates an error.
The following example shows how hierarchy supports unique naming of states.
Each of these states has a unique name because of its location in the hierarchy of the Stateflow diagram. Although the name portion of the label on these states is not unique, when the hierarchy is prefixed to the name in the data dictionary, the result is unique. The full names for these states as seen in the data dictionary are as follows:
The following actions apply to the preceding State Label Example:
Entry Action. State On
has entry
action on_count=0
. The value of on_count
is reset to 0 whenever state On
's entry
action is executed.
During Action. State On
has two during
actions, light_on()
and on_count++.
These actions are executed whenever state On
's during
action is executed.
Exit Action. State Off
has the exit
action light_off()
. This action is executed whenever state Off
's exit
action is executed.
On Event_Name Action. State On
has on power_outage
action. When the event power_outage
occurs, the action handle_outage()
is executed.
See Executing a State for information on how and when entry
, during
, exit
, and on
event_name
actions are taken.
For more detailed information on the action language in transition labels, see Action Language.
![]() | State Decomposition | Transitions | ![]() |