| Stateflow User's Guide | ![]() |
Labeling States
The label for a state specifies its required name for the state and the optional actions executed when the state is entered, exited, or receives an event while it is active.
State labels have the following general format.
name/entry:entry actions during:during actions exit:exit actions bind:dataandeventsonevent_name:on event_name actions
The italicized entries in this format have the following meanings:
| Keyword |
Entry |
Description |
| NA |
name |
A unique reference to the state with optional slash |
entry or en |
entry actions |
Actions executed when a particular state is entered as the result of a transition taken to that state |
during or du |
during actions |
Actions that are executed when a state receives an event while it is active with no valid transition away from the state |
exit or ex |
exit actions |
Actions executed when a state is exited as the result of a transition taken away from the state |
| bind |
events or data |
Binds the specified events or data to this state. Bound data can only be changed by this state or its children, but can be read by other states. Bound events can be broadcast only by this state or its children. |
on |
event_name and on event_name actions |
A specified event and Actions executed when a state is active and the specified event event_name occurs See Adding Events for information on defining and using events. |
Entering the Name
Initially, a state's label is empty. Stateflow indicates this by displaying a ? in the state's label position (upper left corner). Begin the labeling the state by entering a name for the state with the following steps:
Enter the state's name in the first line of the state's label. Names are case sensitive. To avoid naming conflicts, do not assign the same name to sibling states. However, you can assign the same name to states that do not share the same parent.
If you are finished labeling the state, click outside of the state. Otherwise, continue entering actions. To reedit the label, simply click the label text near the character position you want to edit.
Entering Actions
After entering the name of the state in the state's label, you can enter actions for any of the following action types:
entry or en, followed by a colon, followed by one or more action statements on one or more lines. To separate multiple actions on the same line, us a comma or a semicolon.
You can begin entry actions on the same line as the state's name. In this case, begin the entry action with a forward slash (/) instead of the entry keyword.
exit or ex, followed by a colon, followed by one or more action statements on one or more lines. To separate multiple actions on the same line, us a comma or a semicolon.
entry or en, followed by a colon, followed by one or more action statements on one or more lines. To separate multiple actions on the same line, us a comma or a semicolon.
bind followed by a colon, followed by one or more data or events on one or more lines. To separate multiple actions on the same line, us a comma or a semicolon.
on, followed by a space and the name of an event, followed by a colon, followed by one or more action statements on one or more lines, for example
To separate multiple actions on the same line, use a comma or a semicolon. If you want different events to trigger different actions, enter multiple on event_name blocks in the state's label, each specifying the action for a particular event or set of events, for example:
| Note The execution of the actions you enter for a state is dependent only on their action type, and not on the order in which you enter them in the label. |
You can also edit the state's label through the properties dialog for the state. See Changing State Properties.
| Changing State Properties | Outputting State Activity to Simulink | ![]() |
© 1994-2005 The MathWorks, Inc.