| Contents | Index |
| On this page… |
|---|
Converting a State to an Atomic Subchart |
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 Simulink Coder generated code.
To convert state A to an atomic subchart, right-click the state and select Make Contents > Atomic Subcharted. State A changes to an atomic subchart:

Open the properties dialog box for A.
Set Code generation function packaging to Reusable function.
Set Code generation file name options to User specified.
For Code generation file name, enter saturator as the name of the file.
Click OK.
Open the Configuration Parameters dialog box.
In the Code Generation pane, set System target file to ert.tlc.
In the Code Generation > Report pane, select Create code generation report.
This step automatically selects Open report automatically and Code-to-model.
Select Model-to-code.
Click Apply.
In the Configuration Parameters dialog box, go to the Code Generation > Symbols pane.
Set Subsystem methods to the format string $R$N$M$F, where:
$R is the root model name.
$N is the block name.
$M is the mangle string.
$F is the type of interface function for the atomic subchart.
For more information, see Subsystem methods in the Simulink Coder documentation.
Click Apply.
To generate code for your model, click Build on the Code Generation pane of the Configuration Parameters dialog box. 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 string $R$N$M$F specified for Subsystem methods:
$R is the root model name, ex_reuse_states.
$N is the block name, A.
$M is the mangle string, which is empty.
$F is the type of interface function for the atomic subchart, during.
![]() | Tutorial: Dividing a Chart into Separate Units for Editing | Saving and Restoring Simulations with SimState | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |