| Stateflow® | ![]() |
| On this page… |
|---|
Transitions to and from Exclusive (OR) States Transitions to and from Junctions Transitions to and from Exclusive (OR) Superstates |
This example shows simple transitions to and from exclusive (OR) states.

The transition On→Off is valid when state On is active and the event Switch_off occurs. The transition Off→On is valid when state Off is active and event Switch_on occurs.
See Transitions to and from Exclusive (OR) States Examples for more information on the semantics of this notation.
This figure shows transitions to and from a connective junction.

This example is a Stateflow chart of a soda machine. The Stateflow chart is called when the external event Selection_made occurs. The Stateflow chart awakens with the Waiting state active. The Waiting state is a common source state. When the event Selection_made occurs, the Stateflow chart transitions from the Waiting state to one of the other states based on the value of the variable select. One transition is drawn from the Waiting state to the connective junction. Four additional transitions are drawn from the connective junction to the four possible destination states.
See Transitions from a Common Source to Multiple Destinations Example for more information on the semantics of this notation.
This example shows transitions to and from an exclusive (OR) superstate and the use of a default transition.

This is an expansion of the soda machine Stateflow chart that includes the initial example of the On and Off exclusive (OR) states. On is now a superstate containing the Waiting and soda choices states. The transition Off→On is valid when state Off is active and event Switch_on occurs. Now that On is a superstate, this is an explicit transition to the On superstate.
For a transition to a superstate to be valid, the destination substate must be implicitly defined. The destination substate for On is implicitly defined by making the Waiting substate the destination state of a default transition. This notation defines that the resultant transition is made from the Off state to the state On.Waiting.
The transition from On to Off is valid when state On is active and event Switch_off occurs. However, when the Switch_off event occurs, a transition to the Off state must take place no matter which of the substates of On is active. This top-down approach simplifies the Stateflow chart by looking at the transitions out of the superstate without considering all the details of states and transitions within the superstate.
See Default Transition Examples for more information on the semantics of this notation.
The following example shows transitions to and from exclusive (OR) substates.

This Stateflow chart shows a transition from one OR substate to another OR substate: the transition from Waiting.Ready to Orange.In_motion.The transition to the state In_motion is valid when state Waiting.Ready is active and the event Selection_made occurs, providing that the variable select equals 1. This transition defines an explicit exit from the Waiting.Ready state and an implicit exit from the Waiting superstate. On the destination side, this transition defines an implicit entry into the Orange superstate and an explicit entry into the Orange.In_motion substate.
See Transitioning from a Substate to a Substate with Events Example for more information on the semantics of this notation.
A transition segment from a state to a connective junction that has an outgoing transition segment from the connective junction back to the state is a self-loop transition as shown in the following example:

See these sections for examples of self-loop transitions:
Connective Junction — Self-Loop Example
See Self-Loop Transition Example for information on the semantics of this notation.
Connective Junction and For Loops Example
See For-Loop Construct Example for information on the semantics of this notation.
An inner transition is a transition that does not exit the source state. Inner transitions are powerful when defined for superstates with exclusive (OR) decomposition. Use of inner transitions can greatly simplify a Stateflow chart, as shown by the following examples:
This is an example of a Stateflow chart that you can simplify by using an inner transition.

Any event occurs and awakens the Stateflow chart. The default transition to the connective junction is valid. The destination of the transition is determined by [C_one] and [C_two]. If [C_one] is true, the transition to A1 is true. If [C_two] is true, the transition to A2 is valid. If neither [C_one] nor [C_two] is true, the transition to A3 is valid. The transitions among A1, A2, and A3 are determined by E_one, [C_one], and [C_two].
This example simplifies the preceding example using an inner transition to a connective junction.

Any event occurs and awakens the Stateflow chart. The default transition to the connective junction is valid. The destination of the transitions is determined by [C_one] and [C_two].
You can simplify the Stateflow chart by using an inner transition in place of the many transitions among all the states in the original example. If state A is already active, the inner transition is used to reevaluate which of the substates of state A is to be active. When event E_one occurs, the inner transition is potentially valid. If [C_one] is true, the transition to A1 is valid. If [C_two] is true, the transition to A2 is valid. If neither [C_one] nor [C_two] is true, the transition to A3 is valid. This solution is simpler than the previous one.
See Processing the First Event with an Inner Transition to a Connective Junction for more information on the semantics of this notation.
This example shows an inner transition to a history junction.

State Power_on.High is initially active. When event Reset occurs, the inner transition to the history junction is valid. Because the inner transition is valid, the currently active state, Power_on.High, is exited. When the inner transition to the history junction is processed, the last active state, Power_on.High, becomes active (is reentered). If Power_on.Low was active under the same circumstances, Power_on.Low would be exited and reentered as a result. The inner transition in this example is equivalent to drawing an outer self-loop transition on both Power_on.Low and Power_on.High.
See Use of History Junctions Example for another example using a history junction.
See Inner Transition to a History Junction Example for more information on the semantics of this notation.
![]() | Transitions | Default Transitions | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |