A standalone Stateflow® chart is a MATLAB® class that defines the behavior of a finite state machine. Standalone charts implement classic chart semantics with MATLAB as the action language. You can program the chart by using the full functionality of MATLAB, including those functions that are restricted for code generation in Simulink®. For more information, see Create Stateflow Charts for Execution as MATLAB Objects.
You can execute a standalone chart in the MATLAB Command Window or through the Stateflow editor. To enable debugging, set a breakpoint in the standalone chart or in a MATLAB script that executes the chart. Breakpoints interrupt the execution of a chart. While execution is stopped, you can step through each action in the chart, view data values, and interact with the MATLAB workspace to examine the state of the chart.
When debugging a standalone chart that you execute from a MATLAB script, first open the Stateflow editor. Attempting to debug a standalone chart before opening the Stateflow editor at least once can produce unexpected results.
For information on debugging Stateflow charts in Simulink models, see Debugging Charts.
You can set breakpoints on charts, states, and transitions.
To add a breakpoint on a chart, right-click inside the chart and select Set Breakpoint on Chart Entry. This type of breakpoint interrupts the execution before the chart is entered. To remove the breakpoint, right-click inside the chart and clear the Set Breakpoint on Chart Entry option.
To add a breakpoint on a state, right-click the state and select
Set Breakpoint. This type of breakpoint
interrupts the execution before the chart performs the
during actions for the state. To remove the
breakpoint, right-click the state and select Clear
To add a breakpoint on a transition, right-click the transition and select Set Breakpoint. This type of breakpoint interrupts the execution when the transition becomes valid. To remove the breakpoint, right-click the transition and select Clear Breakpoint.
Breakpoints appear as circular red badges. For example, this chart contains
breakpoints on the state
A and on the transition from
To remove all of the breakpoints in a chart, right-click inside the chart and select Clear All Breakpoints In Chart.
When execution stops at a breakpoint, Stateflow enters debugging mode.
The MATLAB command prompt changes to
The Symbols window displays the value of each data object in the chart.
The chart highlights active elements in blue and the currently executing object in green.
For example, when the execution stops at the breakpoint in state
A, the border of the state and the first statement in the
entry action appear highlighted in green.
An execution status badge appears in the graphical object where execution pauses.
Execution stopped before entering a chart or state.
Execution stopped in a state
Execution stopped after exiting a state.
Execution stopped before taking a valid transition.
You can continue the execution from the Stateflow editor, at the debugging prompt, or by selecting a keyboard shortcut.
|Toolbar Icon||Option||Command||Description||Keyboard Shortcut|
Continue execution to the next breakpoint.
Advance to the next step in the chart execution. At the chart level, possible steps include:
For more information, see Execution of a Stateflow Chart.
From a state or transition action that calls a function, advance to the first executable statement in the function.
From a statement in a function containing another function call, advance to the first executable statement in the second function.
Otherwise, advance to the next step in the chart execution. (See the Step Over option.)
From a function call, return to the statement calling the function.
Otherwise, continue execution to the next breakpoint. (See the Continue option.)
Exit debug mode and interrupt the execution.
When you execute the standalone chart from the Stateflow editor, this action removes the chart object from the MATLAB workspace.
In state or transition actions containing more than one statement, you can step through the individual statements one at a time by selecting Step Over. The Stateflow Editor highlights each statement before executing it.
When Stateflow is in debug mode, the Symbols window displays the value of each data object in the chart. You can also examine data values by pointing to a state or a transition in the chart. A tooltip displays the value of each data object used in the selected state or transition.
To test the behavior of your chart, in the Symbols window, you can change the
value of a data object during execution. Alternatively, at the debugging prompt,
enter the new value by using the name
this in place of the chart
object name. For instance, to change the value of the local data
this.x = 7