| Stateflow® | ![]() |
| On this page… |
|---|
Label Format for a State-to-State Transition Example Transitioning from State to State with Events Example Transitioning from a Substate to a Substate with Events Example |
The following example shows the general label format for a transition entering a state.

Stateflow® charts execute this transition as follows:
When an event occurs, state S1 checks for an outgoing transition with a matching event specified.
If a transition with a matching event is found, the condition for that transition ([condition]) is evaluated.
If the condition condition is true, the condition action condition_action ({condition_action}) is executed.
If there is a valid transition to the destination state, the transition is taken.
The transition action transition_action is executed when the transition is taken.
The following example shows the behavior of a simple transition focusing on the implications of whether states are active or inactive.

Initially, the Stateflow chart is asleep. State On and state Off are OR states. State On is active. Event E_one occurs and awakens the chart. Event E_one is processed from the root of the chart down through the hierarchy of the chart:
The Stateflow chart root checks to see if there is a valid transition as a result of E_one. A valid transition from state On to state Off is detected.
The event E_one is broadcast as the transition action.
This second event E_one is processed, but because neither state is active, it has no effect. If the second broadcast of E_one resulted in a valid transition, it would preempt the processing of the first broadcast of E_one. See Early Return Logic for Event Broadcasts.
This sequence completes the execution of the Stateflow chart associated with event E_one when state On is initially active.
Using the same example, what happens when the next event, E_one, occurs while state Off is active?

Again, initially the Stateflow chart is asleep. State Off is active. Event E_one occurs and awakens the chart. Event E_one is processed from the root of the chart down through the hierarchy of the chart with these steps:
The Stateflow chart root checks to see if there is a valid transition as a result of E_one.
A valid transition from state Off to state On is detected.
This sequence completes the execution of the Stateflow chart associated with the second event E_one when state Off is initially active.
Using the same example, what happens when a third event, E_two, occurs?

Notice that the event E_two is not used explicitly in this example. However, its occurrence (or the occurrence of any event) does result in behavior. Initially, the Stateflow chart is asleep and state On is active.
Event E_two occurs and awakens the chart.
Event E_two is processed from the root of the chart down through the hierarchy of the chart.
The chart root checks to see if there is a valid transition as a result of E_two. There is none.
This sequence completes the execution of the Stateflow chart associated with event E_two when state On is initially active.
This example shows the behavior of a transition from an OR substate to an OR substate.

Initially, the Stateflow chart is asleep. State A.A1 is active. Event E_one occurs and awakens the chart. Condition C_one is true. Event E_one is processed from the root of the chart down through the hierarchy of the chart:
The Stateflow chart root checks to see if there is a valid transition as a result of E_one. There is a valid transition from state A.A1 to state B.B1. (Condition C_one is true.)
This sequence completes the execution of this Stateflow chart associated with event E_one.
![]() | Semantic Examples | Condition Action Examples | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |