An atomic subchart is a graphical object that helps you to create standalone subcomponents in a Stateflow® chart. Atomic subcharts are supported only in Stateflow charts in Simulink® models. For more information, see Create Reusable Subcomponents by Using Atomic Subcharts.
Consider this model:
The top Sine Wave block uses a frequency of 1 radian per second, and the bottom Sine Wave block uses a frequency of 2 radians per second. The blocks use the same amplitude (1) and phase shift (0).
In the chart, each state uses saturator logic to convert the input sine wave to an output square wave of the same frequency. The states perform the same actions and differ only in the names of input and output data:
When you run the model, you get the following results:
Suppose that you want to reuse the contents of state A in the chart. You can convert that state to an atomic subchart and then use multiple linked instances of that subchart in your chart.
The sections that follow describe how to replace states in your chart with atomic subcharts. This procedure enables reuse of the same object in your model while retaining the same simulation results.
|1||Change one of the states into an atomic subchart.||Convert a State to an Atomic Subchart|
|2||Create a library that contains this atomic subchart.||Create a Library for the Atomic Subchart|
|3||Replace the states in your chart with linked atomic subcharts.||Replace States with Linked Atomic Subcharts|
|4||Edit the mapping of input and output variables where necessary.||Edit the Mapping of Input and Output Variables|
You can skip the conversion steps and access the new model directly.
To convert state A to an atomic subchart, right-click the state and select Group & Subchart > Atomic Subchart. State A changes to an atomic subchart:
To enable reuse of the atomic subchart you created in Convert a State to an Atomic Subchart, store the atomic subchart in a library:
Create a new library model.
Copy the atomic subchart and paste in your library.
The atomic subchart appears as a standalone chart with an input and an output. This standalone property enables you to reuse the contents of the atomic subchart.
Save your library model.
To replace the states in your chart with linked atomic subcharts:
Delete both states from the chart.
Copy the atomic subchart in your library and paste in your chart twice.
Rename the second instance as B.
Each linked atomic subchart appears opaque and contains the label Link in the upper-left corner.
If you simulate the model now, the output for
You also see warnings about unused data. These warnings appear because atomic
subchart B uses
y1 instead of
y2. To fix these warnings, you
must edit the mapping of input and output variables:
Open the properties dialog box for B.
Click the Mappings tab.
Under Input Mapping, select
u2 from the drop-down list.
The input variable in your atomic subchart now maps to the correct input variable in the main chart.
Under Output Mapping, select
y2 from the drop-down list.
The output variable in your atomic subchart now maps to the correct output variable in the main chart.
When you simulate the new model, the results match those of the original design.
Suppose that you edit the transition from
Neg in the library chart:
This change propagates to all linked atomic subcharts in your main chart. You do not have to update each state individually.