Main Content


Add block to model



h = add_block(source,dest) adds a copy of the block source from a library or model to the specified destination model and block name. This syntax creates the block at the same location as it appears in the model or the library model.

If you are copying between models or from a library, load the destination model first.


h = add_block(source,dest,'MakeNameUnique','on') ensures that the destination block name is unique in the model. This syntax adds a number to the destination block name if a block with that name exists, incrementing to ensure a unique name.

h = add_block(___,'CopyOption','nolink') copies the block or subsystem source from a library without creating a link to the library block.


h = add_block(sourceIn,destIn,'CopyOption','duplicate') duplicates an input port block in a subsystem, giving the destination block the same port number as the source block. Duplicate an input port block to branch a signal from an input port without creating a port or adding lines. For more information, see Create Duplicate Inport Blocks.


h = add_block(___,Name,Value) uses optional Name,Value arguments.

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

With the add_block function, you can use block parameter and value pairs. For a list of all the block parameters, see Common Block Properties and Block-Specific Parameters.


collapse all

Add the block from the Simulink® library to the model f14.

Load or open the destination model.


Add the Scope block from the Simulink Sinks library to f14, naming the new block MyScope.


Add a copy of a block from the model f14 to vdp.

Load or open the destination model.


Add the Actuator Model block from f14 to vdp.

add_block('f14/Actuator Model','vdp/Actuator Model');

Add the block from the Simulink library to the model vdp. Because there is already a block named Scope in vdp, use the MakeNameUnique option to ensure that the new block name is unique.

Load or open the destination model.


Add the Scope block from the Simulink Sinks library to vdp, ensuring that the name is unique.


Add an Inport block in the f14/Controller subsystem that uses the same port number as another Inport block in that subsystem.

Duplicate the Inport block named Stick Input (in) in the Controller subsystem, and name the copy Stick Input (in)2.

add_block('f14/Controller/Stick Input (in)',...
'f14/Controller/Stick Input (in)2','CopyOption','duplicate')

The resulting block uses the same port number as the block named Stick Input (in) but does not add an input port on the parent subsystem. The signal that enters that port branches to both Inport blocks.

Add a block from a library to a model and set parameters using a Name,Value pair.

Load or open the destination model.


Add a Gain block from the library to vdp, and set the Gain value to 5.

add_block('simulink/Math Operations/Gain','vdp/Five','Gain','5')

Input Arguments

collapse all

Block to copy to model, specified as:

  • The full block path if you are copying the block from a model, for example, 'vdp/Mu'. This usage copies the block and its settings.

  • The library block path if you want to add a block from a library, for example, 'simulink/Math Operations/Gain'.

    To get the library block path, you can pause on the block in the Library Browser. Alternatively, you can open the library model, select the block, and enter gcb at the command line. To open the library model, in the Library Browser, right-click the library name in the library list and select Open library_name library.

You can also use the syntax 'built-in/blocktype' as the source block path, where blocktype is the programmatic block name-—the value of the BlockType parameter (see Common Block Properties). However, blocks added using 'built-in/blocktype' sometimes have different default parameter values from library blocks.

For subsystems and masked blocks, use the library block path. Using the BlockType value (SubSystem) creates an empty subsystem.

Example: 'vdp/Mu', 'simulink/Sinks/Scope'

Name and location of the new block in the model, specified as the block path.

Example: 'f14/Controller/MyNewBlock'

Input port block to duplicate, specified as the block path.

Example: 'f14/Controller/Stick Input (in)', 'myModel/mySubsystem/In1'

Input port block to create, specified as the block path. Create the destination block in the same system as the source block.

Example: 'myModel/mySubsystem/DupPortIn'

Output Arguments

collapse all

New block, returned as a handle.

Version History

Introduced before R2006a