Convert Subsystem to Referenced Model
This example demonstrates how to convert a subsystem to a referenced model by using theModel Reference Conversion Advisortool or the
function.Simulink.SubSystem.convertToModelReference
Examine Example Model
Open and simulate the example model.
Thesldemo_mdlref_conversion
model contains an atomic subsystem namedBus 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, createSimulink.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 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.convertToModelReference
function.
Programmatically Convert Subsystem to Referenced Model
Use theSimulink.SubSystem.convertToModelReference
function to programmatically convert the atomic subsystem to a referenced model. To convert the Bus Counter subsystem to a referenced model namedsldemo_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);
另外,双击蓝色块,uses anOpenFcn
block callback to execute this command.