Main Content

Group Blocks into Subsystems

A Subsystem block is a block that contains a subset of a model. You can partition a large model by organizing its contents into Subsystem blocks.

You can have multiple subsystems in a model, and you can have subsystems inside of other subsystems.

By adding subsystems, you create a model hierarchy. Each subsystem you enter takes you one level deeper in the hierarchy.

To view the contents of a subsystem, double-click the Subsystem block. To exit the subsystem, below the left end of the Simulink® Toolbar, click the Back button . For more information on how to navigate the hierarchy of a model with subsystems, see Navigate Model Hierarchy.

You can specify whether a subsystem is evaluated as a single unit when the model runs. Subsystems that evaluate as a single unit are atomic subsystems.

You can also create conditionally executed subsystems that run only when an event occurs on a triggering, function-call, action, or enabling input (see Conditionally Executed Subsystems and Models).

Subsystems can be virtual or nonvirtual:

  • Virtual subsystems help visually organize a block diagram. While they play no active role in the simulation, they can affect the execution order of other blocks.

  • Nonvirtual subsystems play an active role in the simulation of a system. If you add or remove a nonvirtual subsystem, you change the model behavior.

A subsystem is virtual unless it is atomic or conditional.

For more information about subsystems, see Create Subsystems.

Create Subsystems

You can create a subsystem by converting part of an existing model into a subsystem, or by adding a Subsystem block to your model and populating it.

To connect a subsystem, see Connect Subsystems.

Convert Part of Model into Subsystem

To convert part of an existing model into a subsystem:

  1. In the Simulink canvas, click and drag a selection box over the model elements that you want to include in the subsystem. An ellipsis appears next to the selection box.

    Model contains a Transfer Fcn block and a Gain block selected, and an ellipsis next to the selection box

  2. Pause on the ellipsis. An action bar expands.

    Ellipsis replaced by an action bar, with the Create Subsystem option selected

  3. In the action bar, click Create Subsystem.

    In the block diagram, the Transfer Fcn block and a Gain block are replaced by a single Subsystem block. The signal line that connected to the input port of the Transfer Fcn block now connects to the input port of the Subsystem block, and the signal line that connected to the output port of the Gain block now connects to the output port of the Subsystem block.

Create Empty Subsystem

To create an empty subsystem, add a Subsystem block to your model:

  • To open the Quick Insert menu, double-click the Simulink canvas.

  • In the search box, type subsystem.

  • In the list that appears, select the Subsystem entry using your arrow keys.

  • Press Enter.

Create Conditionally Executed Subsystem

To create a conditionally executed subsystem, add the block for the specific type of conditionally executed subsystem you want to implement to your model. The conditionally executed subsystem blocks are in the Simulink library.

You can create these types of conditionally executed subsystems:

For more information on conditionally executed subsystems, see Conditionally Executed Subsystems and Models.

Replace Subsystem with its Contents

To replace a Subsystem block with its contents, select the Subsystem block. Then, in the Simulink Toolstrip, on the Subsystem Block tab, in the Component section, click Expand.

The contents of the subsystem appear in an area labeled Subsystem.

The top image show a Sine Wave block connected to a Subsystem block connected to a Scope block. The bottom image show the same block diagram with the Subsystem block replaced by its contents. The contents are in an area labeled Subsystem.

Specify Whether a Subsystem Is Atomic

To make a subsystem atomic, select the Subsystem block in the canvas. Then, in the Simulink Toolstrip, on the Subsystem Block tab, click Make Atomic.

To make an atomic subsystem nonatomic, select the Subsystem block in the canvas. Then, in the toolstrip, on the Subsystem Block tab, click Atomic Subsystem.

Determine Whether Subsystem Is Virtual

To determine if a subsystem is virtual, use the get_param function with the Boolean block parameter IsSubsystemVirtual.

For example, check whether the Abs subsystem in the If-Then-Else Blocks example is a virtual subsystem:

  1. To open the example, enter this command in the MATLAB® Command Window.

    openExample('simulink_features/IfThenElseBlocksExample');
  2. To check whether the Abs subsystem is virtual, enter this command.

    get_param('sldemo_ifsub/Abs','IsSubsystemVirtual')

    The command window returns this output:

    'off'

    The Abs subsystem is not virtual because it is a conditionally executed subsystem.

Specify Subsystem Read/Write Permissions

You can specify these read/write permissions for a subsystem:

  • ReadWrite

  • ReadOnly

  • NotReadorWrite

To specify the read/write permissions for a subsystem:

  1. To open the Block Parameters dialog box, right-click the Subsystem block and select Block Parameters.

  2. In the Block Parameters dialog box, on the Main tab, select the Read/Write permissions option you want.

  3. Click OK.

Subsystem Block Parameters dialog box with the Read/Write Permissions list expanded, and ReadOnly selected

Save Subsystem as Separate File

The contents of a Subsystem block are saved with the model. If you want to save the contents in a separate file, use a Subsystem Reference block instead. For more information, see Reference a Subsystem File in a Model.

See Also

Related Topics