Add block to model


h = add_block(source,dest)
h = add_block(source,dest,'MakeNameUnique','on')
h = add_block(sourceIn,destIn,'CopyOption','duplicate')
h = (___,Name,Value)



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(sourceIn,destIn,'CopyOption','duplicate') duplicates an inport block in a subsystem, giving the destination block the same port number as the source block. Duplicate an inport to branch a signal from an input port without creating a port or adding lines. For more information, see Creating Duplicate Inports.


h = (___,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 single 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 in that subsystem.

Duplicate the Stick Input (in) block in the Controller subsystem, naming the copy Stick Input (in)2. The resulting block uses the same port number as Stick Input (in) but does not add an inport on the parent subsytem. The signal that enters that port branches to both inports.

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

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 name if you are copying the block from another model, for example, 'vdp/Mu'. This usage copies the block and its settings.

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

    To get the library block path name, you can hover over 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 name, 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 name. 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 name.

Example: 'f14/Controller/MyNewBlock'

Inport block whose port number to copy, specified as the block path name.

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

Inport block with duplicate port number to create, specified as the block path name. 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.

Introduced before R2006a

Was this topic helpful?