Documentation Center

  • Trial Software
  • Product Updates

Simulink.BlockDiagram.createSubSystem

Create subsystem containing specified set of blocks

Syntax

Simulink.BlockDiagram.createSubSystem(blocks)
Simulink.BlockDiagram.createSubSystem()

Description

Simulink.BlockDiagram.createSubSystem(blocks) creates a new subsystem and moves the specified blocks into the subsystem. All of the specified blocks must originally reside at the top level of the model or in the same existing subsystem within the model.

If any of the blocks have unconnected input ports, the command creates input port blocks for each unconnected input port in the subsystem and connects the input port block to the unconnected input port. The command similarly creates and connects output port blocks for unconnected output ports on the specified blocks. If any of the specified blocks is an input port, the command creates an input port block in the parent system and connects it to the corresponding input port of the newly created subsystem. The command similarly creates and connects output port blocks for each of the specified blocks that is an output port block.

Simulink.BlockDiagram.createSubSystem() creates a new subsystem in the currently selected model and moves the currently selected blocks within the current model to the new subsystem.

Input Arguments

blocks

An array of block handles

Default: []

Examples

The following function converts the contents of a model or subsystem into a subsystem.

function convert2subsys(sys)
  blocks = find_system(sys, 'SearchDepth', 1);
  bh = [];
  for i = 2:length(blocks)
    bh = [bh get_param(blocks{i}, 'handle')];
  end
  Simulink.BlockDiagram.createSubSystem(bh);
end

For example, suppose you create the following model and save it as initial_model.slx.

Executing

convert2subsys('initial_model');

converts this model to create a subsystem:

See Also

| | |

Was this topic helpful?