Main Content

Convert Subsystem to a Referenced Subsystem

This example shows how you can convert a Subsystem block in a model or library to a Subsystem Reference block.

Convert Subsystem Block in a Model to a Subsystem Reference Block

Consider a model sldemo_mdlref_conversion with a Subsystem block Bus Counter that models a counter algorithm.

To convert the Bus Counter Subsystem block to a Subsystem Reference block:

1. Select the Bus Counter block. On the Subsystem Block tab, select Convert > Convert to Referenced Subsystem. A dialog box opens.

2. Enter a valid MATLAB® name such as Bus_Counter in the Subsystem file name field. If a test harness is associated with the subsystem, you can select the Transfer test harnesses check box to save the test harnesses of the subsystem with the subsystem file.

3. Click Convert. The Subsystem block changes into a Subsystem Reference block with the name of the subsystem file Bus_Counter displayed at the top of the block icon. The subsystem file contains the Bus Counter subsystem and is saved in the current directory.

When you convert a subsystem to a referenced subsystem, the Subsystem Reference block automatically inherits the properties of its input and output signals. You do not need to explicitly define the interface for the Subsystem Reference block.

Alternatively, to convert the block programmatically, enter this command in the MATLAB Command Window.

'sldemo_mdlref_conversion/Bus Counter','Bus_Counter');

For more information, see convertSubsystemToSubsystemReference.

4. Save the model.

Convert Library Subsystem Block to Subsystem Reference Block

You can also convert Library Subsystems (Simulink Coder) to referenced subsystems using the same steps as converting a Subsystem block to a Subsystem Reference block in a model. However, you must unlock the library before conversion and then save the library to preserve the changes made during the conversion process.

When you convert a library subsystem block to a Subsystem Reference block, all the linked instances of the library Subsystem block are converted to subsystem reference. Alternatively, you can also convert only a specific instance of a linked subsystem. First break the link of the instance to the parent library and then perform the conversion. For more information on breaking links to libraries, see Disable or Break Links to Library Blocks.

Conditions to Convert to Referenced Subsystems

A block cannot be converted to a referenced subsystem when:

  • The block is read-only.

  • The block is a Configurable Subsystem, Variant Subsystem, Stateflow, or Simulink Function.

  • The block is an injector subsystem or a linked subsystem, except when the value of the Link Status parameter of the linked block is none.

  • The block is the component under test inside the test harness.

  • The block is masked with its contents hidden using 'MaskHideContents'.

  • The block has a child block with a test harness.

  • The block is inside models that have AUTOSAR or Software architectures.

  • The state owner and accessor blocks are not inside the same subsystem.

See Also



Related Topics