Main Content

Convert Subsystem to Referenced Model

This example demonstrates how to convert a subsystem to a referenced model by using theModel Reference Conversion Advisortool or theSimulink.SubSystem.convertToModelReferencefunction.

Examine Example Model

Open and simulate the example model.

Thesldemo_mdlref_conversionmodel contains an atomic subsystem namedBus Counterthat 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, createSimulink.Busobjects 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 theSubsystem Blocktab, selectConvert > Model Block. In the Model Reference Conversion Advisor, setNew model nametosldemo_bus_counter, then clickConvert.

You can also open the Model Reference Conversion Advisor by setting'UseConversionAdvisor'to'true'when calling theSimulink.SubSystem.convertToModelReferencefunction.

Programmatically Convert Subsystem to Referenced Model

Use theSimulink.SubSystem.convertToModelReferencefunction to programmatically convert the atomic subsystem to a referenced model. To convert the Bus Counter subsystem to a referenced model namedsldemo_bus_counterand 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);

另外,双击蓝色块,uses anOpenFcnblock callback to execute this command.

See Also

Blocks

Tools

Functions

Related Topics