| Contents | Index |
| On this page… |
|---|
State Inconsistencies in a Chart Conflicting Transitions in a Chart |
States in a Stateflow chart are inconsistent if they violate any of these rules:
An active state (consisting of at least one substate) with exclusive (OR) decomposition has exactly one active substate.
All substates of an active state with parallel (AND) decomposition are active.
All substates of an inactive state with either exclusive (OR) or parallel (AND) decomposition are inactive.
An error occurs at compile time when the following conditions are all true:
A transition leads to a state that has exclusive (OR) decomposition and multiple substates. There are no default paths that lead to the entry of any substate. This condition results in a state inconsistency error. (However, if all transitions into that state are supertransitions leading directly to the substates, there is no error.)
The state with multiple substates does not contain a history junction.
You can control the level of diagnostic action that occurs due to omission of a default transition in the Diagnostics > Stateflow pane of the Configuration Parameters dialog box. For more information, see the documentation for the No unconditional default transitions diagnostic.
The following chart has a state inconsistency.

In the absence of a default transition indicating which substate is to become active, the chart has a state inconsistency error.
Adding a default transition to one of the substates resolves the state inconsistency.

Conflicting transitions are two equally valid paths from the same source in a Stateflow chart during simulation. In the case of a conflict, Stateflow software evaluates equally valid transitions based on ordering mode in the chart: explicit or implicit.
For explicit ordering (the default mode), evaluation of conflicting transitions occurs based on the order you specify for each transition. For details, see Explicit Ordering of Outgoing Transitions.
For implicit ordering, evaluation of conflicting transitions occurs based on internal rules described in Implicit Ordering of Outgoing Transitions.
To detect conflicting transitions during a simulation:
The following chart has two conflicting transitions:

How the Transition Conflict Occurs. The default transition to state A assigns data a equal to 1 and data b equal to 10. The during action of state A increments a and decrements b during each time step. The transition from state A to state B is valid if the condition [a > 4] is true. The transition from state A to state C is valid if the condition [b < 7] is true. During simulation, there is a time step where state A is active and both conditions are true. This issue is a transition conflict.
If you select the Transition Conflict check box in the debugger, you get a run-time error. If you do not select the check box, resolution of the transition conflict depends on the ordering you use for evaluation of outgoing transitions.
Conflict Resolution for Explicit Ordering When Check Box Is Not Selected. For explicit ordering, the chart resolves the conflict by evaluating outgoing transitions in the order that you specify explicitly. For example, if you right-click the transition from state A to state C and select Execution Order > 1 from the context menu, the chart evaluates that transition first. In this case, the transition from state A to state C occurs.
Conflict Resolution for Implicit Ordering When Check Box Is Not Selected. For implicit ordering, the chart evaluates multiple outgoing transitions with equal label priority in a clockwise progression starting from the twelve o'clock position on the state. In this case, the transition from state A to state B occurs.
The Stateflow debugger detects the following data range violations during simulation:
When a data object equals a value outside the range of the values set in the Initial value, Minimum, and Maximum fields specified in the Data properties dialog box
See Setting Data Properties in the Data Dialog Box for a description of the Initial value, Minimum, and Maximum fields in the Data properties dialog box.
When the result of a fixed-point operation overflows its bit size
See Detecting Overflow for Fixed-Point Types for a description of the overflow condition in fixed-point numbers.
When you select Saturate on integer overflow for your chart, the debugger does not flag any cases of integer overflow during simulation. However, the debugger continues to flag out-of-range data violations based on minimum-and-maximum range checks. For more information, see Impact of Saturation on Debugger Checks.
To detect data range violations during a simulation:
The following chart has a data range violation.

Assume that the data a has an Initial value and Minimum value of 0 and a Maximum value of 2. Each time an event awakens this chart and state A is active, a increments. The value of a quickly becomes a data range violation.
Cyclic behavior is a step or sequence of steps that is repeated indefinitely (recursive). The Stateflow debugger uses cycle detection algorithms to detect a class of infinite recursions caused by event broadcasts.
To detect cyclic behavior during a simulation:
This chart shows how an event broadcast can cause infinite recursive cycles.

When the state C during action executes, event E1 is broadcast. The transition from state A.A1 to state A.A2 becomes valid when event E1 is broadcast. Event E2 is broadcast as a condition action of that transition. The transition from state B.B1 to state B.B2 becomes valid when event E2 is broadcast. Event E1 is broadcast as a condition action of the transition from state B.B1 to state B.B2. Because these event broadcasts of E1 and E2 are in condition actions, a recursive event broadcast situation occurs. Neither transition can complete.
This chart shows an example of cyclic behavior in a flow graph that the debugger cannot detect.

The data object i is set to 0 in the condition action of the default transition. i increments in the next transition segment condition action. The transition to the third connective junction is valid only when the condition [i < 0] is true. This condition is never true in this flow graph, resulting in a cycle.
The debugger cannot detect this cycle because it does not involve recursion due to event broadcasts. Although the debugger cannot detect cycles that depend on data values, a separate diagnostic error does appear during simulation, for example:
Junction is part of a cycle and does not have an unconditional path leading to termination.
For information on fixing cyclic behavior in flow graphs, type the following at the MATLAB command prompt:
sfhelp('cycle_error');This chart shows an example of noncyclic behavior that the debugger flags as being cyclic.

State A becomes active and i is initialized to 0. When the transition is tested, the condition [i < 5] is true. The condition actions that increment i and broadcast the event E are executed. The broadcast of E when state A is active causes a repetitive testing (and incrementing of i) until the condition is no longer true. The debugger flags this behavior as a cycle, but the so-called cycle breaks when i becomes greater than 5.
![]() | Example of Debugging Run-Time Errors in a Chart | Guidelines for Avoiding Unwanted Recursion in a Chart | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |