| Stateflow User's Guide | ![]() |
Simulating a Stateflow Diagram
Stateflow allows you to observe the behavior of Stateflow diagrams in Simulink models during simulation of the model. Before you simulate a Stateflow diagram, you make sure that simulation is enabled for your model as you did in Setting Up Diagram Simulation.
When you simulate a Simulink model containing Stateflow blocks, Stateflow builds an application for each Stateflow block that graphically executes its Stateflow diagram by highlighting the active state and the executing transition. By simulating your Stateflow diagrams, you understand the behavior that you specify for them, and find out if they are behaving as you expect them to.
Simulate the SFcontrol1 model as described in the following steps:
SFcontrol1 model, position the Simulink model window and the Controller Stateflow diagram window so that they can both be seen at once with no overlap.
This is displayed as "Ready (ICED)" at the bottom of the Stateflow diagram window, where "ICED" is an internal Stateflow designation.
Parsing the Stateflow diagram ensures that the notations you specified are valid and correct. If any critical errors are found, they are displayed in a Stateflow Builder window and simulation is halted. If no errors are found, the window does not appear, and simulation continues.
The following example window results from an error introduced into the Controller diagram by removing the name of the On state.
Critical error messages are displayed with a red button. You can display the full text of an error message in the bottom pane by clicking on it in the top pane. If you double-click an error message in the top pane, the Stateflow diagram editor appears with the error-causing object highlighted.
The simulation application that Stateflow generates for simulation is referred to as an sfun target. Stateflow creates a directory called sfprj in the current MATLAB directory if the directory does not already exist. Stateflow uses this directory to store the generated files that make up the sfun target.
| Stateflow begins in simulation mode. The Controller diagram is active, but nothing in it is. |
event.
The event causes the Stateflow diagram to execute and look for the first available transition, which is the default transition into the state Off. You see the following simulation sequence:
event that causes the Stateflow diagram to look for an available transition. You see the following continued simulation behavior:event that causes the Stateflow diagram to look for an available transition. You see the following continued simulation behavior: | Setting Up Diagram Simulation | Using the Debug Tool During Simulation | ![]() |
© 1994-2005 The MathWorks, Inc.