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

You can add a block from a library using the add_block function with these input arguments:

  • The library block path from top level of Library Browser tree hierarchy to the library block you want to add, for example, 'Simulink/Math Operations/Gain'

  • The full block path path from top level of model hierarchy to where you want to add the new block, for example, 'myModel/mySubsystem/myblock'

Both paths must end in a block name.

In this example, you add a customizable circular gauge to the Controller subsystem in the f14 model.

Open the example. Then, load or open the destination model.


Suppose you do not know the exact name of the block needed to complete this task or the location of the block in the Library Browser tree. To get the library block path, do a keyword search in the Library Browser. Open the Library Browser. In the search box, type gauge and press Enter.

In the search results, pause on the circular gauge icon. A tooltip displays the library block path.

Add the Circular Gauge block to the Controller subsystem. Name the block myGauge.

  • The library block path is 'simulink_hmi_customizable_blocks/Circular Gauge'.

  • The full block path is 'f14/Controller/myGauge'.

add_block('simulink_hmi_customizable_blocks/Circular Gauge','f14/Controller/myGauge');

To see the block, in the f14 model, navigate into the Controller subsystem.


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

Load or open the destination model.


Add the Actuator Model block from the f14 model to the vdp model.

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

Add a Scope block from the Simulink® library to the model vdp. Because the vdp model already contains a block named Scope, 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 the vdp model, 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. 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 argument.

Load or open the destination model.


Add a Gain block from the library to the vdp model. Then, 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