Main Content
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 Code and Executables for Individual Subsystems
Generate and build a standalone executable from a subsystem. - 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. - 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
- Function Reuse in Generated Code
This example shows how to configure an atomic subsystem for generating reusable code. - Determine Why Subsystem Code Is Not Reused
Determine why the code generator does not reuse subsystem code as you expect. - Generate Reusable Code from Model Reference Hierarchy
Generate reusable subsystem code from a top model with Model blocks. - Generate Reentrant Code from Subsystems
Generate reusable, reentrant code from subsystems. - Generate Reusable Code from For Each Subsystems
Generate reusable code for For Each subsystems that perform the same processing.