Subsystem reference allows you to save the contents of a subsystem in a separate SLX file and reference it using a Subsystem Reference block. You can create multiple instances referencing the same subsystem file. When you edit any instance of a referenced subsystem, the changes are saved in the separate SLX file in which the subsystem is stored and all the referenced instances of that file are synchronized.
When you save a subsystem to a separate file you can reuse it multiple times by using Subsystem Reference blocks referencing the same subsystem file.
You can identify a Subsystem Reference block by the triangles in the opposite corners of the block icon.
A referenced subsystem supports all the semantics of a regular subsystem. A referenced subsystem adapts itself to the context of the parent model and has identical execution behavior when compared to a nonreferenced subsystem.
A subsystem file stores the content of a subsystem in an SLX file.
A subsystem file:
Cannot be simulated.
Does not have a configuration set.
Does not have a model workspace.
Does not have code generation capability.
To create a subsystem file:
On the Start Page, in the Simulink product group, click Blank Subsystem.
Alternatively, in the Simulink toolstrip, on the Simulation tab, select New and click Blank Subsystem. A Subsystem window opens.
Add content and click Save.
Specify a file name in the Save As dialog box. The file name must be a valid MATLAB name.
This creates a new subsystem file at the location specified.
To create a subsystem file programmatically, use the command:
For more information on controlling subsystem files programmatically, see Control Referenced Subsystem Programmatically.
Open a model in which you want to reference a subsystem file.
Add a Subsystem Reference block using the Simulink Library Browser or the Quick Block Insert menu. An empty Subsystem Reference block is added to the Simulink canvas.
Double-click the Subsystem Reference block.
In the Block Parameter dialog box, specify the name of the subsystem file or click Browse to navigate to it.
Click OK to save the changes.
You can convert an existing Subsystem block to a Subsystem Reference block.
Consider a model with two Subsystem blocks as shown.
In this model, you have two Subsystem blocks – a Controller subsystem and a Plant subsystem. To convert the Controller Subsystem block to a referenced subsystem:
Select the Controller Subsystem block and on the Subsystem Block tab, select Convert and click Convert to Subsystem Reference.
Specify a name for the subsystem component in the Subsystem file name field and click Convert. The name must be a valid MATLAB name. The conversion creates a subsystem file in the current directory. To create the file in a specific location, click Browse and navigate to the save location.
The Subsystem block changes into a Subsystem Reference block with the name of the subsystem file displayed at the top of the block icon.
When you convert a linked block to a referenced subsystem, do so in the parent library block of that linked block. Once you convert a parent library block to a referenced subsystem, all its linked block instances are also converted to referenced subsystems.
You cannot convert a subsystem to a referenced subsystem when the subsystem:
Has a test harness associated to it.
Has no read/write permissions.
Is a library block that has a self-modifiable mask.
In a model containing multiple instances of a referenced subsystem, you can edit any instance and upon saving the changes the updates propagate to all the referenced instances. When you actively edit an instance of a referenced subsystem, all the other referenced instances are locked and are unavailable for edit.
A badge is shown at the bottom left corner of an open subsystem file to denote the availability of the file for edit. The badge shows two states:
indicates that the subsystem file is available for edit. Right-click the badge to see all the active instances of that subsystem and to navigate to each of them.
indicates that the subsystem file is unavailable for edit, as another instance is being actively edited. Right-click the badge to open the instance being edited.
Once you have edited an instance in a model, you can save the changes from the Save option available in the Simulation tab of the model window. The Save All drop-down gives you two options to save your changes:
Save All – To save all the updates in the current model.
Save Specific Referenced File – To save a specific subsystem file when you have made changes to multiple subsystem files.
If you edit any instance of a referenced subsystem in a model, save the changes before updating or simulating the model. Unsaved changes in referenced instances cause error during simulation.
You can mask a subsystem file using a model mask. When you create a model mask for a subsystem file, all the referenced instances share the same model mask.
To mask a subsystem file:
Open the subsystem file to be masked.
In the Simulink toolstrip, on the Modeling tab, Component gallery, click Create Model Mask. Alternatively, right-click anywhere on the canvas and select Mask and click Create Model Mask. The Mask Editor dialog opens.
Add mask parameters and click OK.
You cannot directly mask a Subsystem Reference block. To mask a Subsystem Reference block, right-click the block and select Mask > Open file and Create Model Mask . This action opens the subsystem file being referenced and creates a model mask on it.
For more information on creating and editing model masks, see Introduction to Model Mask.
When you export a model containing referenced subsystems to a version prior to R2019b, all the Subsystem Reference blocks are converted to independent Subsystem blocks.
Subsystem files cannot be exported to a version prior to R2019b. For information on how to export a simulink model to a previous version, see Export a Model to a Previous Simulink Version.
You can create a referenced subsystem, find available referenced subsystems in a model, change the referenced subsystem file in a block, and check the block diagram type of an SLX file using a command-line interface.
You can create a referenced subsystem using the new_system command:
You can find if a model contains a referenced subsystem using the find_system command:
find_system(bdroot, 'RegExp','on','BlockType','SubSystem','ReferencedSubsystem', '.')
This command returns a list of Subsystem Reference blocks in the model.
find_system lists all the child blocks inside a subsystem
If you do not want
find_system to look inside a referenced
LookInsideSubsystemReference set to
LookInsideSubsystemReference is set to
You can change the subsystem file being referenced in a Subsystem
Reference block through command-line interface using the
set_param(gcb, 'ReferencedSubsystem', '<subsystemfilename>')
You can check if an SLX file is a subsystem block diagram type that can be placed in a Subsystem Reference block using any of these commands:
logical 1if bdname.slx is a Subsystem block diagram type and
logical 0if it is not. When using this command, make sure that bdname.slx is loaded.
This command returns
Subsystem if bdname.slx is a Subsystem block
diagram type. When using this command, make sure that bdname.slx is loaded.
This command gives the entire model information where the
BlockDiagramType property is shown as
bdname.slx is a Subsystem block diagram type.
While using a referenced subsystem in a model:
To mask a referenced subsystem, use a model mask.
Do not reference a parent subsystem because it creates a reference loop.
Only the subsystem file type can be referenced by a Subsystem Reference block.