Documentation

Convert a Subsystem to a Referenced Model

Determine Whether to Convert the Subsystem

Before you convert a subsystem to model referencing, consider whether model referencing is the approach to use to meet your modeling requirements.

Model referencing offers several benefits for modeling large, complex systems and for team-based development. However, subsystems or libraries are better suited for some modeling goals than model referencing. Many large models involve using a combination of subsystems and referenced models. For information to help you to decide whether to convert a subsystem to a referenced model, see Componentization Guidelines.

Confirm that the subsystem you want to convert is a type of subsystem that you can convert. See Subsystems That You Can Convert.

Update the Model Before Converting the Subsystem

    Tip   Before you perform the conversion, make sure that the model containing the subsystem that you want to convert compiles successfully.

The advisor fixes or guides you through fixing issues. However, if you are converting a large, complex subsystem, consider taking steps before you convert the model. Preparing the model and subsystem can eliminate or reduce the number of issues the advisor identifies. It can be more efficient to address issues in the model editing environment than to switch repeatedly between the advisor and the Simulink® Editor.

    Note:   You can use Model Reference Conversion Advisor Fix option to have the advisor fix some conversion issues.

  1. Set the Configuration Parameters > Diagnostics > Data Validity > Signal resolution parameter to Explicit only or None.

    You can use the Model Reference Conversion Advisor Fix option to address this issue automatically.

  2. Configure these subsystem interfaces to the model.

    Subsystem InterfaceWhat to Look ForModel Modification

    Goto or From blocks

    Crossing of subsystem boundaries

    Use an Inport block to replace From blocks that have a corresponding GoTo block that crosses the subsystem boundary.

    Use an Outport block to replace each GoTo block that has corresponding From blocks that cross the subsystem boundary.

    Connect the Inport and Outport blocks to the corresponding subsystem ports.

    You can use the Model Reference Conversion Advisor Fix option to address this issue.

    Data stores

    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.Signal object. For details, see Data Stores with Signal Objects.

    You can use the Model Reference Conversion Advisor Fix option to address this issue.

    Tunable parameters

    Global tunable parameters in the dialog box opened using the Configuration Parameters > Optimization > Signals and Parameters > Configure button

    Use tunablevars2parameterobjects to create a Simulink.Parameter object for each tunable parameter.

    The Simulink.Parameter objects must have a storage class other than Auto.

    For more information, see Parameterize Instances of a Reusable Referenced Model and Tunable Parameters.

    You can use the Model Reference Conversion Advisor Fix option to address this issue.

  3. Configure the subsystem and its contents.

    Subsystem ConfigurationWhat to Look ForModel Modification

    Inactive subsystem variants

    Variant Subsystem blocks.

    Make the subsystem variant that you want to convert active. The advisor does not convert inactive subsystem variants.

    To have the new Model block behave similar to the subsystem variant, convert each variant subsystem separately and then use a Model Variants block. For more information, see Set up Model Variants.

    Function calls

    Function-call signals that cross virtual subsystem boundaries.

    Move the Function-Call Generator block into the subsystem that you want to convert.

      Note:   If you convert an export-function subsystem, then you do not need to move the Function-Call Generator block.

    Function-call outputs.

    Change the function-call outputs to data triggers.

    Wide function-call ports.

    Eliminate wide signals for function-call subsystems.

    Sample times

    Sample time of an Inport block that does not match the sample time of the block driving the Inport.

    Insert Rate Transition blocks where appropriate.

    Inport blocks

    Merged Inport blocks.

    Configure the model to avoid merged Inport blocks. See the Merge block documentation.

    Constant blocks

    Constant blocks that input to subsystems.

    Consider moving the Constant blocks into the subsystem.

    Buses

    Bus signals that enter and exit a subsystem.

    Match signal names and bus element names for blocks inside the subsystem.

    Consider using the Configuration Parameters > Diagnostics > Connectivity > Signal label mismatch diagnostic.

    Duplicate signal names in buses.

    Make signal names of the 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 namelengthmax function.

    Change any invalid signal names to be valid MATLAB identifiers.

Run the Model Reference Conversion Advisor

Before you run the advisor, make sure that the model containing the subsystem that you want to convert compiles successfully.

  1. Open the model and locate the subsystem that you want to convert.

  2. For improved conversion performance, close any open Scope block windows.

  3. Start the Model Reference Conversion Advisor. In the Simulink Editor, right-click the subsystem that you want to convert. Select Subsystem & Model Reference > Convert Subsystem to > Referenced Model.

  4. In the Model Reference Conversion Advisor dialog box, review the default settings under Input Parameters. Modify the parameters for running the advisor as needed and click Apply.

      Tip   The advisor provides context-sensitive help for checks. In the advisor, right-click the check (such as Check conversion input parameters) and select What's This?.

      Note:   The advisor can compare simulation results for the top model for the referenced model to the results for the baseline model containing the subsystem. Select Check simulation results after conversion. For details, see Compare Simulation Results Before and After Conversion.

  5. Click Convert.

  6. Address any issues that the advisor reports. For some issues, the advisor provides a Fix button to address an issue.

  7. After you address each issue, click Continue until all the checks pass.

Compare Simulation Results Before and After Conversion

The advisor can compare simulation results before and after the conversion.

Before you convert the subsystem:

  • In the Model Reference Conversion Advisor, under Input Parameters, select Replace subsystem with a Model block and Check simulation results after conversion.

  • Set these options:

    • Stop time

    • Absolute tolerance

    • Relative tolerance

  • Enable signal logging for the subsystem output signals of interest.

  • Set the Model block simulation mode option in the advisor to the same simulation mode as the original model.

After you convert the model, select View comparison results. The results display in the Simulation Data Inspector. A green check mark indicates that the simulation results are the same for the baseline model and the model with the referenced model.

For more information about the Simulation Data Inspector, see View and Analyze Simulation Results.

Revert the Conversion Results

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, select Click here to restore the original model.

Integrate the Referenced Model into the Parent Model

After you complete the conversion, update the model as necessary to meet your modeling requirements.

Add a Model Block, If Necessary

If, before the conversion, you cleared the Replace the content of a subsystem with a Model block option, then add a Model block to the parent model manually.

  1. Delete the Subsystem block.

  2. Copy the new Model block into the model, where the subsystem was.

    Note:   If you enable the Replace the content of a subsystem with a Model block option, the advisor action depends on whether you use the automatic fix options.

    • If you use the automatic fixes, then the advisor replaces the Subsystem block with a Model block unless the automatic fixes change the input or output ports. If the ports change, then the advisor includes the contents of the subsystem in a Model block that is inserted in the Subsystem block.

    • If you do not use the automatic fixes, then the advisor replaces the Subsystem block with a Model block.

Inspect Root Inport Blocks in the 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. For details, see the documentation for the Interpolate data parameter of the Inport block.

Convert Each Variant Subsystem

If you convert an active variant subsystem, convert each of the variant subsystems to referenced model. Converting each variant subsystem to a referenced model produces similar results to using the Variant Subsystem block.

Related Examples

More About

Was this topic helpful?