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, seeCreate Reusable Subcomponents by Using Atomic Subcharts.
Original Model Without Atomic Subcharts
This model contains twoSine 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 stateA
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 stateA
and selectGroup & Subchart > Atomic Subchart. StateA
changes to an atomic subchart and displays the labelAtomicin 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 toA
, recompilation occurs only for the atomic subchart and not the entire chart.
See Also
Sine Wave(Simulink)