As a model increases in size and complexity, you can simplify it by grouping blocks into subsystems. A subsystem is a set of blocks that you group into a single Subsystem block.
Establishes a hierarchical block diagram where a Subsystem block is on one layer and the blocks that make up the subsystem are on another.
Keeps functionally related blocks together.
Helps reduce the number of blocks displayed in your model window.
Establishes an interface with inputs and outputs.
When you make a copy of a subsystem, that copy is independent of the source subsystem. To reuse the contents of a subsystem across a model or across models, consider referenced subsystems, referenced models, or subsystems linked to a block in a custom library. For more information, see Choose Among Types of Model Components.
Types of Subsystems
A subsystem can be virtual or nonvirtual. A virtual subsystem provides graphical hierarchy in a model and does not impact the execution of a model. A nonvirtual subsystem executes as a single unit within a model.
For controllers and other standalone components, define a hard boundary around the related blocks by using a nonvirtual subsystem or referenced model. Defining a hard boundary upfront avoids costly refactoring when you want to generate code for the component.
Simulink® classifies nonvirtual subsystems into these types:
|Type of Subsystem||Description|
Subsystem that executes as a single unit.
Subsystem whose execution is enabled by external input.
Subsystem whose execution is triggered by external input.
Subsystem whose execution is controlled by an external function-call input.
|Enabled and Triggered Subsystem|
Subsystem whose execution is enabled and triggered by external inputs.
Subsystem whose block states reset with an external trigger.
|If Action Subsystem|
Subsystem whose execution is enabled by an If block.
|Switch Case Action Subsystem||Subsystem whose execution is controlled by a Switch Case block.|
|While Iterator Subsystem|
Subsystem that repeats execution during a simulation time step while a logical condition is true.
|For Iterator Subsystem||Subsystem that repeats execution during a simulation time step for a specified number of iterations.|
|For Each Subsystem|
Subsystem that repeats execution on each element or subarray of input signal and concatenates results.
To create a subsystem, you can:
In the Simulink Editor, double-click and start typing the subsystem type, then select the corresponding block from the menu.
In the Simulink Editor, drag a selection box to outline the subsystem that you want to create, then select the subsystem type.
Drag a Subsystem block from the Library Browser.
Copy and paste a Subsystem block from a model.
When you create a subsystem from a selection box, the selection can be empty or can contain multiple blocks in one area of the model.
From the action bar, select the type of subsystem that you want to create.
When the selection contains blocks that correspond to input and output ports, the new subsystem includes copies of those blocks. The new subsystem does not contain copies of blocks that correspond to control ports.
You can change the type of subsystem after creation.
To make a subsystem execute as a unit, click the Subsystem block. On the Subsystem tab, select Is Atomic Subsystem.
To make a subsystem execute conditionally, add a block that corresponds to a control port.
To make a subsystem execute unconditionally, remove blocks that correspond to control ports.
Add Ports to Subsystems
The ports on a Subsystem block correspond to blocks inside the subsystem.
For example, this Subsystem block has two input ports and one output port.
The subsystem contains two Inport blocks,
In2, and one Outport block,
that correspond to the ports on the Subsystem block.
To automatically add ports to a Subsystem block:
Click the edge of the Subsystem block, then select the type of port to create.
Drag a line to the edge of the Subsystem block.
The corresponding port blocks are added inside the subsystem.
After automatic port creation, the port label on the Subsystem block is enabled for quick editing. See, Edit Port Labels on Subsystems.
To manually add ports, open the subsystem by double-clicking the Subsystem block, then add the corresponding blocks to the subsystem.
|Type of Port||Corresponding Block|
|Signal port, input||Inport block|
|Signal port, output||Outport block|
|Bus port, input||In Bus Element block|
|Bus port, output||Out Bus Element block|
|Control port, enabled||Enable block|
|Control port, triggered||Trigger block|
|Control port, function-call||Trigger block with Trigger
type set to |
|Control port, reset||Reset block|
|Control port, action||Action Port block|
|Connection port||Connection Port (Simscape) block|
To change the location of a port on a Subsystem block, drag the port to a new location on any side of the Subsystem block.
By default, Simulink labels the ports on a Subsystem block. To specify how Simulink labels the ports of a subsystem:
Select the Subsystem block.
On the Format tab of the Simulink Toolstrip, select one of the labeling options from the Port Labels menu. For more information, see Show port labels.
Edit Port Labels on Subsystems
You can directly edit the port labels on these types of subsystem blocks:
Subsystem with mask
To edit the port label on a subsystem block in the current model:
Point to the port label. An interactive port label cue (blue box surrounding the port label) appears. Click the cue.
Alternatively, select the port and press F2. The cue enters edit mode.
Creating a new port on a Subsystem block using automatic port creation also enables the port label cue for quick editing.
A port selector cue appears above the port label cue to indicate the port label information (port block name, signal name, bus port, or connection port) that is being edited. For signal ports, you can edit both the port block name and the port signal name from the port label. To switch between the values, click the respective icon in the selector cue or use the keyboard shortcuts Ctrl+1,2.
Enter a value in the port label cue and press Enter or Esc, or click away.
After the port label is edited, Simulink automatically updates the name of the related port or signal within the subsystem.
To make successive port label edits on a subsystem block:
Select a port on the block.
Edit the port label and press Enter. This action enables keyboard selection of ports.
You can select adjacent ports using the up arrow or down arrow key and pressing F2 for quick editing.
This table lists the update action depending on the type of port label defined on the subsystem block.
Type of port label Action None Editing not supported. Port icon
Updates the names of elements in the subsystem depending on the Icon display parameter of the port.
For example, if the value of the Icon display parameter of the port is
Signal name, then both the icon on the port block and the name of the linked signal are updated.
For this type of port label, the information shown on the port label after an edit depends on the final edit performed on the label using the selector cue:
If the initial port label shows the port block name, and the final edit is on the signal name, then the Icon display parameter for the underlying port block automatically updates to
Signal name. So, after the edit, the port label shows the signal name by default.
If the initial port label shows the port signal name, and the final edit is on the port block name, then the Icon display parameter for the underlying port block automatically updates to
Port number. So, after the edit, the port label shows the block name by default.
Port block name Updates the block name of the port in the subsystem. For this type of port label, you can edit only the port block name using the port selector cue. Signal name Updates the name of the signal linked to the port.
Simulink does not show the port selector cue for Chart blocks.
Editing port labels on Subsystem blocks with a mask icon is not supported.
Editing port numbers from the port label is not supported. You can still edit the port block name and signal name using the port label cue.
Editing name of propagated signals from the port label is not supported. You can still edit the port block name and internal signal name using the port label cue. When you click the cue, the port signal name field is empty because the internal signal does not have a name.
Subsystem port labels show the name of propagated signals when all these conditions are true:
The value of the Icon display parameter for the underlying port block is
The internal signal within the subsystem is connected but does not have a name.
The propagated signal has a name.
You can change the name of the Subsystem block and modify the block the way that you do with any other block. For example, you can:
Apply block masks to hide the subsystem content, making it appear as an atomic block with its own icon and parameter dialog box. For more information, see Masking Fundamentals.
Use block callbacks to perform actions in response to subsystem modeling actions such as handling an error, deleting a block or line in a subsystem, or closing a subsystem. For more information on block properties, such as callbacks, see Specify Block Properties.
Restrict Subsystem Access
The Read/Write permissions parameter of a Subsystem block controls the level of access allowed for the subsystem.
Restricting read or write access does not prevent the access restrictions from being changed. To hide proprietary information, consider using a protected model. For more information, see Explore Protected Model Capabilities.
When a subsystem is stored in a custom library, you can use the Read/Write permissions parameter on the parent library block to control access for the linked instances of the block. As long as the library link remains intact, the restricted access can prevent people from viewing or modifying the contents of the subsystem while still allowing them to employ it in a model. For more information, see Linked Blocks.