Main Content

Simulink.BlockDiagram.createSubsystem

Create subsystem containing specified set of blocks

Description

example

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 connectsInportandOutportblocks to them inside the subsystem.

If any of the blocks are input or output port blocks, the function createsInportandOutportblocks in the parent system to connect to the corresponding ports on the newSubsystemblock.

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

example

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

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 theSimulink.findBlocksfunction.

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 theSimulink.findBlocksfunction.

bh = Simulink.findBlocks('CreateSubsystemModel');

Replace the contents of the model with a subsystem namedss1that 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 theSimulink.findBlocksorgcbhfunctions.

Data Types:double

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis 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 encloseNamein 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 forNameis already used in the diagram:

  • 'on'— Uses the next available increment of the name. For example, ifNameis 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 theNameargument.

Data Types:char|string

版本嗨story

Introduced in R2009a