Convert Subsystems to Referenced Models
Model reference offers benefits for modeling large, complex systems and for team-based development. Many large models use a combination of subsystems and referenced models. To decide whether to convert a subsystem to a referenced model, see Choose Among Types of Model Components.
Prepare Subsystem for Conversion
Preparing a subsystem for conversion can eliminate or reduce the number of issues identified during conversion. Addressing these issues before conversion can be more efficient than switching repeatedly between the diagnostic messages and the Simulink® Editor.
To prepare the subsystem:
Set the Signal resolution configuration parameter to
You can automatically fix this issue during conversion.
Configure the Subsystem block interface.
You can automatically fix these interface issues during conversion.
Subsystem Interface What to Look For Model Modification
Goto or From blocks
Goto or From blocks crossing the subsystem boundary
Replace From blocks that have a corresponding Goto block that crosses the subsystem boundary with an Inport block.
Replace each Goto block that has corresponding From blocks that cross the subsystem boundary with an Outport block.
Connect the Inport and Outport blocks to the corresponding subsystem ports.
Data Store Memory blocks accessed by Data Store Read or Data Store Write blocks from outside of the subsystem
Replace the Data Store Memory block with a global data store. Define a global data store using a
Simulink.Signalobject. For details, see Data Stores with Signal Objects.
Global tunable parameters in the dialog box opened using the Configuration Parameters > Code Generation > Optimization > Configure button
Simulink.Parameterobjects must have a storage class other than
For more information, see Parameterize Instances of a Reusable Referenced Model and Tunable Parameters.
Configure the Subsystem block contents.
Subsystem Configuration What to Look For Model Modification Block execution order
Virtual subsystem that does not force contained blocks to execute consecutively.
Select the Subsystem block, and then on the Subsystem Block tab, select Is Atomic Subsystem.
Function-call signals that cross virtual subsystem boundaries
Move the Function-Call Generator block into the subsystem that you want to convert.
If you convert an export-function subsystem, then you do not need to move the Function-Call Generator block.
Change the function-call outputs to data triggers.
Wide function-call ports
Eliminate wide signals for function-call subsystems.
An Inport block sample time that does not match the sample time of the block driving the Inport block
Insert Rate Transition blocks where appropriate.
Merged Inport blocks
Configure the model to avoid merged Inport blocks. See the Merge block documentation.
Constant blocks that provide input for subsystems
Move Constant blocks into the subsystem.
Buses that enter and exit a subsystem
Match signal names and bus element names for blocks inside the subsystem.
To find signal names that do not match bus element names, use the Signal label mismatch diagnostic.
Duplicate signal names in buses
Make signal names of bus elements unique.
Signal names that are not valid MATLAB® identifiers. A valid identifier is a character vector that meets these conditions:
The name contains letters, digits, or underscores.
The first character is a letter.
The length of the name is less than or equal to the value returned by the
Change any invalid signal names to be valid MATLAB identifiers.
Make sure that the model containing the subsystem that you want to convert compiles successfully.
Convert Subsystems to Referenced Models
To convert a subsystem to a referenced model:
Select the Subsystem block you want to convert.
In the Simulink Toolstrip, on the Subsystem Block tab, select Convert > Model Block.
The Model Reference Conversion Advisor opens and lets you interactively specify conversion parameters and fix issues that the advisor finds.
To make the conversion process faster:
In the Model Reference Conversion Advisor, select Fix errors automatically (if possible). This option automatically fixes some conversion issues, but you do not control the fixes.
Close any open Scope block windows before starting the conversion.
To leave the Subsystem block in place and create a separate model from the contents of the Subsystem block, clear Replace the content of a subsystem with a Model block.
To compare top-model simulation results before and after conversion:
Enable signal logging for output signals of interest.
Select Check simulation results after conversion and Replace the content of a subsystem with a Model block.
Set the Stop time, Absolute tolerance, and Relative tolerance.
Set the Model block simulation mode option in the advisor to the same simulation mode as the original model.
After you set the conversion settings, click Convert and address any identified issues.
Alternatively, in the MATLAB command window, use the
Simulink.SubSystem.convertToModelReference function. You can convert
multiple Subsystem blocks using one
Simulink.SubSystem.convertToModelReference command. However, you
cannot convert a parent subsystem and a child of that subsystem at the same time.
After all conversion checks pass, Simulink:
Creates a referenced model from the subsystem.
Simulink.Signalobjects, and tunable parameters that the referenced model requires.
By default, replaces the Subsystem block with a Model block that references the new model.
Inserts the Model block in a Subsystem block if the automatic fixes added ports to the Model block interface.
Creates an HTML conversion summary report in the
slprjfolder. This report summarizes the results of the conversion process, including the results of the fixes that the advisor performed. This report also describes the elements that it copies.
Optionally checks the consistency of simulation results before and after conversion.
Simulink copies the following elements from the original model to the new referenced model.
Configuration set — If the parent model uses:
A configuration set that is not a referenced configuration set, the advisor copies the entire configuration set to the referenced model
A referenced configuration set, then both the parent and referenced models use the same referenced configuration set
Variables — The advisor copies only the model workspace variables that the subsystem used in the original model to the model workspace of the referenced model. If the model that contained the subsystem uses a data dictionary, then the referenced model uses the same data dictionary.
Requirements links — The advisor copies requirements links created with Requirements Toolbox™ software to the Model block from the original Subsystem block.
Compare Simulation Results Before and After Conversion
After you successfully complete conversion, use the Click here to view the comparison results link. The results display in the Simulation Data Inspector. A green check mark indicates that simulation results are within tolerance between the baseline model and the model with the new referenced model.
For more information, see Compare Simulation Data.
If you are not satisfied with the conversion results, you can restore the model to its initial state. Use one of these approaches:
At any point during the conversion, select File > Load Restore Point.
After you successfully run the Complete conversion check, use the Click here to restore the original model link.
Integrate Referenced Model into Parent Model
After you complete the conversion, update the model as necessary to meet your modeling requirements. For example, you can manually replace a Subsystem block with a Model block that references the created referenced model.
If you want to simulate the model with external data, check that the root Inport blocks in the new referenced model have the appropriate Interpolate data parameter setting. See the documentation for the Interpolate data parameter of the Inport block.