| Stateflow User's Guide | ![]() |
State Action Types
States can have different action types, which include entry, during, exit, bind, and, on event_name actions. The actions for states are assigned to an action type using label notation with the following general format:
name/entry:entry actionsduring:during actionsexit:exit actionsbind:data_name,event_nameonevent_name:on event_name actions
The following example shows examples of state action types:
After you enter the name in the state's label, enter a carriage return and specify the actions for the state. A description of each action type is given in the following topics:
Entry Actions
Entry actions are preceded by the prefix entry or en for short, followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,). 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 specifying entry actions only.
Entry actions are executed for a state when the state is entered (becomes active). In the preceding example in State Action Types, the entry action id = x+y is executed when the state A is entered by the default transition.
For a detailed description of the semantics of entering a state, see Entering a State and State Execution Example.
Exit Actions
Exit actions are preceded by the prefix exit or ex for short, followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,).
Exit actions for a state are executed when the state is active and a transition out of the state is taken.
For a detailed description of the semantics of exiting a state, see Exiting an Active State and State Execution Example.
During Actions
During actions are preceded by the prefix during or du for short, followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,).
During actions are executed for a state when it is active and an event occurs and no valid transition to another state is available.
For a detailed description of the semantics of executing an active state, see Executing an Active State and State Execution Example.
Bind actions are preceded by the prefix bind, followed by a required colon (:), followed by one or more events or data. Separate multiple data/events with a carriage return, semicolon (;), or a comma (,).
Bind actions bind the specified data and events to a state. Data bound to a state can be changed by the actions of that state or its children. Other states and their children are free to read the bound data, but they cannot change it. Events bound to a state can be broadcast only by that state or its children. Other states and their children are free to listen for the bound event, but they cannot send it.
Bind actions are applicable to a Stateflow diagram whether the binding state is active or not. In the preceding example in State Action Types, the bind action bind: id, time_out for state A binds the data id and the event time_out to state A. This forbids any other state (or its children) in the Stateflow diagram from changing id or broadcasting event time_out.
If another state includes actions that change data or send events that are bound to another state, a parsing error results. The following example demonstrates a few of these error conditions:
Binding a function-call event to a state also binds the function-call subsystem that it calls. In this case, the function-call subsystem is enabled when the binding state is entered and disabled when the binding state is exited. For a detailed description of this feature, see Using Bind Actions to Control Function-Call Subsystems.
On Event_Name Actions
On event_name actions are preceded by the prefix on, followed by a unique event, event_name, followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,). You can specify actions for more than one event by adding additional on event_name lines for different events. If you want different events to trigger different actions, enter multiple on event_name action statements in the state's label, each specifying the action for a particular event or set of events, for example:
On event_name actions for a state are executed when the state is active and the event event_name is received by the state. This is also accompanied by the execution of any during actions for the state.
For a detailed description of the semantics of executing an active state, see Executing an Active State.
| Defining Action Types | Transition Action Types | ![]() |
© 1994-2005 The MathWorks, Inc.