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.
Assume that you have the following model, and the chart has two states:
Suppose that you want to generate reusable code so that you can perform unit testing on state A. You can convert that part of the chart to an atomic subchart and then specify a separate file to store the generated code.
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:
Open the properties dialog box for A.
Set Code generation function packaging to
Set Code generation file name options to
For Code generation file name, enter
saturator as the name of the
Open the Model Configuration Parameters dialog box.
In the Code Generation pane, set
System target file to
In the Code Generation > Report pane, select Create code generation report.
This step automatically selects Open report automatically and Code-to-model.
In the Model Configuration Parameters dialog box, go to the Code Generation > Symbols pane.
Set Subsystem methods to the format scheme
$R is the root model name.
$N is the block name.
$M is the mangle token.
$F is the type of interface
function for the atomic subchart.
For more information, see Subsystem methods (Simulink Coder).
To generate code for your model, press Ctrl+B. In the code generation report that appears, you see a separate file that contains the generated code for the atomic subchart.
To inspect the code for
saturator.c, click the hyperlink in the
report to see the following code:
Line 28 shows that the
during function generated for the atomic
subchart has the name
ex_reuse_states_A_during. This name
follows the format scheme
$R$N$M$F specified for
$R is the root model name,
$N is the block name,
$M is the mangle token, which is empty.
$F is the type of interface function for the atomic
The line numbers shown can differ from the numbers that appear in your code generation report.