| Stateflow® | ![]() |
The general label format for a transition segment entering a junction is the same as for transitions entering states, as shown in the following example.

Execution of a transition in this example occurs as follows:
When an event occurs, state S1 is checked for an outgoing transition with a matching event specified.
If a transition with a matching event is found, the transition condition for that transition (in brackets) is evaluated.
If condition_1 evaluates to true, the condition action condition_action (in braces) is executed.
The outgoing transitions from the junction are checked for a valid transition. Since condition_2 is true, a valid state-to-state transition (S1 to S2) is found.
State S1 is exited (including execution of S1's exit action).
The completed state-to-state transition (S1 to S2) is taken.
State S2 is entered (including execution of S2's entry action).
This example shows the behavior of an if-then-else decision construct.

Initially, the Stateflow® chart is asleep. State A is active. Event E_one occurs and awakens the chart. Condition [C_two] 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 segment from state A to the connective junction. The transition segments beginning from a 12 o'clock position on the connective junction are evaluated for validity. The first transition segment, labeled with condition [C_one], is not valid. The next transition segment, labeled with the condition [C_two], is valid. The complete transition from state A to state C is valid.
This sequence completes the execution of this Stateflow chart associated with event E_one.
This example shows the behavior of a self-loop transition using a connective junction.

Initially, the Stateflow chart is asleep. State A is active. Event E_one occurs and awakens the chart. Condition [C_one] is false. 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 segment from state A to the connective junction. The transition segment labeled with a condition and action is evaluated for validity. Because the condition [C_one] is not valid, the complete transition from state A to state B is not valid. The transition segment from the connective junction back to state A is valid.
This sequence completes the execution of this Stateflow chart associated with event E_one.
This example shows the behavior of a for loop using a connective junction.

Initially, the Stateflow chart is asleep. State A is active. Event E_one occurs and awakens the Stateflow chart. Event E_one is processed from the root of the Stateflow chart down through the hierarchy of the Stateflow 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 segment from state A to the connective junction. The transition segment condition action, i = 0, is executed and completed. Of the two transition segments leaving the connective junction, the transition segment that is a self-loop back to the connective junction is evaluated next for validity. That segment takes priority in evaluation because it has a condition specified, whereas the other segment is unlabeled.
The condition [i < 10] is evaluated as true. The condition actions i++ and a call to func1 are executed and completed until the condition becomes false. A connective junction is not a final destination; thus the transition destination remains to be determined.
The unconditional segment to state B is now valid. The complete transition from state A to state B is valid.
This sequence completes the execution of this Stateflow chart associated with event E_one.
This example shows the behavior of a Stateflow chart that uses flow notation.

Initially, the Stateflow chart is asleep. State A.A1 is active. The condition [C_one()] is initially true. 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. There is no valid transition.
State A checks itself for valid transitions and detects a valid inner transition to a connective junction.
The next possible segments of the transition are evaluated. There is only one outgoing transition and it has a condition action defined. The condition action is executed and completed.
The next possible segments are evaluated. There are two outgoing transitions; one is a conditional self-loop transition and the other is an unconditional transition segment. The conditional transition segment takes precedence. The condition [C_one()] is tested and is true; the self-loop transition is taken. Since a final transition destination has not been reached, this self-loop continues until [C_one()] is false.
Assume that after five iterations [C_one()] is false.
The next possible transition segment (to the next connective junction) is evaluated. It is an unconditional transition segment with a condition action. The transition segment is taken and the condition action, {d=my_func()}, is executed and completed. The returned value of d is 84.
The next possible transition segment is evaluated. There are three possible outgoing transition segments to consider. Two are conditional; one is unconditional. The segment labeled with the condition [d<100] is evaluated first based on the geometry of the two outgoing conditional transition segments. Because the return value of d is 84, the condition [d<100] is true and this transition (to the destination state A.A1) is valid.
This sequence completes the execution of this Stateflow chart associated with event E_one.
This example shows the behavior of transitions from a common source to multiple conditional destinations using a connective junction.

Initially, the Stateflow chart is asleep. State A 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 Stateflow chart root checks to see if there is a valid transition as a result of E_two. There is a valid transition segment from state A to the connective junction. Given that the transition segments are equivalently labeled, evaluation begins from a 12 o'clock position on the connective junction and progresses clockwise. The first transition segment, labeled with event E_one, is not valid. The next transition segment, labeled with event E_two, is valid. The complete transition from state A to state C is valid.
This sequence completes the execution of this Stateflow chart associated with event E_two.
This example shows the behavior of transitions from multiple sources to a single destination using a connective junction.

Initially, the Stateflow chart is asleep. State A 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. There is a valid transition segment from state A to the connective junction and from the junction to state C.
This sequence completes the execution of this Stateflow chart associated with event E_one.
This example shows the behavior of transitions from multiple sources to a single destination based on the same event using a connective junction.

Initially, the Stateflow chart is asleep. State B 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. There is a valid transition segment from state B to the connective junction and from the junction to state C.
This sequence completes the execution of this Stateflow chart associated with event E_one.
This example shows the behavior of transitions with junctions that force backtracking behavior in flow graphs.

Initially, state A is active and conditions c1, c2, and c3 are true:
The Stateflow chart root checks to see if there is a valid transition from state A.
There is a valid transition segment marked with the condition c1 from state A to a connective junction.
Condition c4 is not true; therefore control flow is backtracked to state A.
The chart root checks to see if there is another valid transition from state A.
There is a valid transition segment marked with the condition c2 from state A to a connective junction.
Condition c4 is not true; therefore control flow is backtracked to state A.
The preceding example shows the unanticipated behavior of executing both actions a1 and a2 and executing action a3 twice. To resolve this problem, consider this design.

This example provides two junctions that allow flow to end if either c3 or c4 is not true. This leaves state A active without taking any unnecessary actions.
![]() | Inner Transition Examples | Event Actions in a Superstate Example | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |