Main Content

Create Subsystems

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.

Using subsystems:

  • 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.

Tip

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 SubsystemDescription
Atomic Subsystem

Subsystem that executes as a single unit.

Enabled Subsystem

Subsystem whose execution is enabled by external input.

Triggered Subsystem

Subsystem whose execution is triggered by external input.

Function-Call Subsystem

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.

Resettable Subsystem

Subsystem whose block states reset with an external trigger.

If Action Subsystem

Subsystem whose execution is enabled by an If block.

Switch Case Action SubsystemSubsystem 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 SubsystemSubsystem 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.

Create Subsystems

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 (In1 and In2) and one Outport block (Out1) that correspond to the ports on the Subsystem block.

To add ports to a subsystem:

  • 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.

  • Open the subsystem by double-clicking the Subsystem block, then add the corresponding blocks to the subsystem.

    Type of PortCorresponding Block
    Signal port, inputInport block
    Signal port, outputOutport block
    Bus port, inputIn Bus Element block
    Bus port, outputOut Bus Element block
    Control port, enabledEnable block
    Control port, triggeredTrigger block
    Control port, function-callTrigger block with Trigger type set to function-call
    Control port, resetReset block
    Control port, actionAction Port block
    Connection portConnection 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.

A port is dragged from the left side of the block to the top side of the block.

By default, Simulink labels the ports on a Subsystem block. To specify how Simulink labels the ports of a subsystem:

  1. Select the Subsystem block.

  2. 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.

Configure Subsystems

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.

Note

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 Protected Models for Model Reference.

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.

See Also

Related Topics