Main Content

Convert Subsystem to Referenced Model

This example demonstrates how to convert a subsystem to a referenced model by using the Model Reference Conversion Advisor tool or the Simulink.SubSystem.convertToModelReference function.

Examine Example Model

Open and simulate the example model.

The sldemo_mdlref_conversion model contains an atomic subsystem named Bus Counter that models a counter algorithm.

The subsystem interface uses In Bus Element and Out Bus Element blocks to pass a virtual bus into and out of the subsystem. The virtual buses inherit their data types. To more strongly define the interface of the new model after conversion, create Simulink.Bus objects and use them as the data types of the buses.

Interactively Convert Subsystem to Referenced Model

Use the Model Reference Conversion Advisor to interactively convert the subsystem. Select a Subsystem block, then on the Subsystem Block tab, select Convert > Model Block. In the Model Reference Conversion Advisor, set New model name to sldemo_bus_counter, then click Convert.

You can also open the Model Reference Conversion Advisor by setting 'UseConversionAdvisor' to 'true' when calling the Simulink.SubSystem.convertToModelReference function.

Programmatically Convert Subsystem to Referenced Model

Use the Simulink.SubSystem.convertToModelReference function to programmatically convert the atomic subsystem to a referenced model. To convert the subsystem named Bus Counter to a referenced model named sldemo_bus_counter and to replace the Subsystem block with a Model block that references the new model, enter this command in the MATLAB® Command Window:

Simulink.SubSystem.convertToModelReference(...
    'sldemo_mdlref_conversion/Bus Counter', ...
    'sldemo_bus_counter', ...
    'ReplaceSubsystem', true);

See Also

Blocks

Tools

Functions

Related Topics