Reduce the Compilation Time of a Chart
This example shows how to use atomic subcharts to reduce the compilation time when testing a sequence of changes in a Stateflow® chart. Atomic subcharts are not supported in standalone Stateflow charts in MATLAB®. For more information, see Create Reusable Subcomponents by Using Atomic Subcharts.
Original Model Without Atomic Subcharts
This model contains two Sine Wave (Simulink) blocks: one with a frequency of 1 radian per second, and the other with a frequency of 2 radians per second.
In the chart, each state uses saturator logic to convert the input sine wave to an output square wave of the same frequency.
Because this example does not use atomic subcharts, every time that you make a change to the chart and start simulation, recompilation occurs for the entire chart.
In contrast, you can convert state A
to an atomic subchart. When you modify the atomic subchart, recompilation occurs for only the subchart and not for the entire chart. As a result, incremental builds for simulation require less time to recompile.
Edit Model to Use Atomic Subcharts
Step 1: Convert a State to an Atomic Subchart
Right-click state A
and select Group & Subchart > Atomic Subchart. State A
changes to an atomic subchart and displays the label Atomic in the upper-left corner.
Step 2: Start the Simulation
Before simulating, compilation occurs for the entire chart.
Step 3: Modify the Atomic Subchart
Double-click the atomic subchart
A
. The contents of the subchart appear in the Stateflow Editor.In the state
Pos
, change the entry action toy1 = 2;
In the state
Neg
, change the entry action toy1 = -2;
Step 4: Restart the Simulation
After the changes to A
, recompilation occurs only for the atomic subchart and not the entire chart.
See Also
Sine Wave (Simulink)