Simulink.BlockDiagram.createSubsystem

Create subsystem containing specified set of blocks

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(blocks,'Name',MySubsystemName ) creates a new subsystem with a specified name.

Simulink.BlockDiagram.createSubsystem(___,'MakeNameUnique') creates a new subsystem with a unique name.

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

Examples

collapse all

  1. Use this function to set up the conversion of 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
  2. Create a model and save it as initial_model.slx.

  3. Execute this code to convert the model to create a subsystem.

    convert2subsys('initial_model');

Input Arguments

collapse all

An array of block handles.

Name of the new subsystem, specified as a character vector or string scalar.

Specify a unique name for the new subsystem. Specifying no returns an error.

Example: Simulink.BlockDiagram.createSubsystem(myBlocks, 'Name', 'MySubsystemName',"MakeNameUnique",'yes')

Introduced in R2009a