Main Content

Simulink.BlockDiagram.createSubsystem

Create subsystem containing specified set of blocks

Description

Simulink.BlockDiagram.createSubsystem(blocks) creates a subsystem and moves the specified blocks into it. All of the specified blocks must originally reside in the same block diagram.

If any of the blocks have unconnected ports, the function creates and connects Inport and Outport blocks to them inside the subsystem.

If any of the blocks are input or output port blocks, the function creates Inport and Outport blocks in the parent system to connect to the corresponding ports on the new Subsystem block.

example

Simulink.BlockDiagram.createSubsystem() replaces the currently selected blocks with a new subsystem that contains those blocks.

Simulink.BlockDiagram.createSubsystem(___,Name,Value) specifies options using one or more name-value pair arguments in addition to the input arguments in previous syntaxes. For example, 'Name','MySubsystem' names the new subsystem 'MySubsystem'.

example

Examples

collapse all

Open or load the example model.

CreateSubsystemModel

Get the block handles for all blocks at the top level of the model by using the Simulink.findBlocks function.

bh = Simulink.findBlocks('CreateSubsystemModel');

Replace the contents of the model with a subsystem that contains the model contents.

Simulink.BlockDiagram.createSubsystem(bh);

Open or load the example model.

CreateSubsystemModel

Get the block handles for all blocks at the top level of the model by using the Simulink.findBlocks function.

bh = Simulink.findBlocks('CreateSubsystemModel');

Replace the contents of the model with a subsystem named ss1 that contains the model contents.

Simulink.BlockDiagram.createSubsystem(bh,'Name','ss1');

Input Arguments

collapse all

Block handles, specified as a numeric array. To get block handles, use the Simulink.findBlocks or gcbh functions.

Data Types: double

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: Simulink.BlockDiagram.createSubsystem(blocks, 'Name', 'MySubsystemName')

Name of the new subsystem, specified as the comma-separated pair consisting of 'Name' and a character vector or string scalar.

Data Types: char | string

Option to make the subsystem name unique, specified as the comma-separated pair consisting of 'MakeNameUnique' and 'on' or 'off'.

If the value that you specify for Name is already used in the diagram:

  • 'on' — Uses the next available increment of the name. For example, if Name is set to 'Controller' and the diagram already contains a block named 'Controller', the function names the new subsystem 'Controller1'.

  • 'off' — Returns an error.

Dependencies

To use this parameter, specify a value for the Name argument.

Data Types: char | string

Version History

Introduced in R2009a