Subsystems
Generate and reuse code for subsystems
You can group blocks into a Subsystem block to reduce the size and complexity of a model. To generate modular code and unit test code for individual subsystems, you can configure an atomic subsystem to generate code to a separate function and file.
A subsystem can be virtual or atomic. A virtual subsystem provides graphical hierarchy in a model and does not impact the execution of a model. An atomic subsystem executes as a single unit within a model. The code generator supports conditionally executed subsystems.
Topics
Code Generation
- Generate Subsystem Code as Separate Function and Files
Configure subsystems to generate functions in separate files and specify the names of those functions and files. - Generate Predictable Function Interface to Match Graphical Block Interface
Generate a nonreusable subsystem function interface that does not change. - Generate Code for Variant Subsystem Blocks
Generate code for specific implementation of component represented using Variant Subsystem block. - Specify Generated Code Function Packaging for Subsystems
This example shows how to configure how the code generator generates code for an atomic subsystem. - Modeling Guidelines for Generated Code
Overview of guidelines to consider for your model and generated code, including coding guidelines, component deployment modeling guidelines, and MathWorks Advisory Board guidelines (MAB).
Code Optimization
- Generate Inlined Subsystem Code
Configure nonvirtual subsystems to generate inlined code.
Code Reuse
- Generate Reentrant Code from Subsystems
Reduce generated code size by configuring subsystems to generate shared and reentrant functions. - Resolve Issues with Reusable Subsystems Generating Separate Functions
Troubleshoot reusable subsystems generating separate functions or producing name collision errors. - Use Signal Conversion or Bias Blocks to Resolve Issues with Reusable Code Generation
Place blocks to prevent the code generator from considering reusable subsystems to be unequal. - Compare Checksums to Determine Why Generated Code Is Not Reused
Programmatically compute differences between reusable subsystem interfaces and contents.