| Stateflow | ![]() |
Run a Simulation
These steps show how to run a simulation:
On_off Stateflow block to display the Stateflow diagram.
sfun).
on/off switch manual switch (double click it) between its inputs, 0 and 1.
on/off switch sends on_switch and off_switch events to the Stateflow chart. These events toggle the chart's active state from Off to On and back to Off again.
Both the on_switch and off_switch events are defined as Input from Simulink events. This means that the events are input to the chart from Simulink, in this case, from a manual switch. When the input to the on/off switch rises from 0 to 1, this sends an on_switch event to the On_Off chart because on_switch is defined as a rising trigger. Similarly, when the input to the on/off switch falls from 1 to 0, this sends an off_switch event to the chart because the off_switch event is defined as a falling trigger.
value of temp switch to change the value of the data temp from 20 to 40.
on/off switch again and notice the difference.
temp, the transition from the Off state to the On state no longer takes place. The transition from Off to On passes through a junction which has an alternate path back to Off. Because the alternate path has a condition, it gets priority. In this case, the condition evaluates to true (nonzero) and the alternate path is taken.
| 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 | ![]() |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |