Stateflow | ![]() ![]() |
Run a Simulation
These steps show how to run a simulation:
On_off
Stateflow block to display the Stateflow diagram.
sfun
is the simulation target for any Stateflow blocks. Stateflow displays code generation status messages in the MATLAB Command Window. Before starting the simulation, Stateflow temporarily sets the model to read-only to prevent accidental modification while the simulation is running. This is displayed as "Ready (ICED)" where the term "ICED" is an internal Stateflow designation.
The input from the Sine Wave block is defined as the Input from Simulink event Switch
. When the simulation starts, the Stateflow diagram is animated, reflecting the state changes triggered by the input sine wave. Each input event of Switch
toggles the model between the Power_off
and Power_on
states.
Note Running a simulation might require setting up the tools used to build Stateflow targets. See Setting Up the Target Compiler for more information. |
Where Stateflow Generates Code for Simulation
When you simulate a Simulink model containing Stateflow charts (as you did in the previous section), Stateflow generates a Simulink S-function (sfun
) target that enables Simulink to simulate the Stateflow blocks. The sfun
target can be used only with Simulink.
Before generating code, Stateflow creates a directory called sfprj
in the current MATLAB directory if the directory does not already exist. Stateflow uses the sfprj
directory during code generation to store generated files. See the section Generated Files.
Note
Do not confuse the sfprj directory created in the MATLAB current directory for generated files with the sfprj directory in the directory containing the model file (see the section Save the Model). The latter sfprj directory is used for storing information on the model, while the former stores generated files. However, if the MATLAB current directory is the model directory, the same sfprj directory (under the model directory) is used to store both model information and generated files.
|
If you have the Stateflow Coder, you can generate stand-alone code suitable for a particular processor. See Building a Target for more information on code generation.
![]() | Parse the Stateflow Diagram | Debug the Model During Simulation | ![]() |