Quantcast

Documentation Center

  • Trial Software
  • Product Updates

add_block

Add block to model

Syntax

add_block('src', 'dest')
block = add_block('src', 'dest')
add_block('src', 'dest', 'param1', value1, ...)
add_block('src', 'dest', 'MakeNameUnique', 'on')
add_block('src_inport', 'dest_inport', 'CopyOption', 'duplicate')
add_block('built-in/Note', 'path/text', 'Position', position_array)

Description

add_block('src', 'dest') copies the block with the full path name that you specify with 'src' to a new block with a full path name that you specify with 'dest'. The block parameters of the new block are identical to those of the original. The new block appears in front of any blocks that it overlaps. If the 'src' block is a Subsystem block, then add_block copies all the blocks in the subsystem.

block = add_block('src', 'dest') returns the handle of the newly created block.

add_block('src', 'dest', 'param1', value1, ...) creates a copy of the 'src' block, with the named parameters having the specified values. Additional arguments must occur in parameter/value pairs.

add_block('src', 'dest', 'MakeNameUnique', 'on') creates a unique name for the new block, based on the name of the 'dest' block. The add_block function creates a unique name only if the 'dest' block name exists in the model into which you add the new block. By default, MakeNameUnique is off.

add_block('src_inport', 'dest_inport', 'CopyOption', 'duplicate') applies only to Inport blocks. It creates a copy with the same port number as the 'src_inport' block.

add_block('built-in/Note', 'path/text', 'Position', position_array) creates a an annotation in a Simulink® model or a note in a Stateflow® chart. The first part of the path/text argument is the path of the model or chart where you want the annotation or note. Append to the path a backslash (/), followed by the text for the annotation or note. The position_array argument is a 1x4 array, specified as [left, top, right, bottom], that gives the position of the left top corner of the annotation or note in pixels, relative to the upper left corner of the model or chart. If the annotation is autosized (the default), you can specify a 1x2 array [left top]. Positive x and y values are to the right of and down from the origin, respectively, and negative x and y values are to the left of up from the origin, respectively.

Before you add a block from a source model, open the source model. For example, use load_system (model opens invisibly) or open_system (model opens visibly). Also open the destination model if it is different from the source model.

Calling add_block triggers the CopyFcn and PreCopyFcn block callback functions.

You can use 'built-in/blocktype' as a source block path name for Simulink built-in blocks, where blocktype is the built-in block type (that is, the value of its BlockType parameter (see Common Block Properties). However, using 'built-in/blocktype' causes some default parameter values of some blocks to be different from the defaults that you get if you added those blocks interactively using Simulink.

Tips

Do not use delete_block to delete an annotation. For details, see Delete an Annotation.

Examples

Copy the Scope block from the Sinks subsystem of the simulink system to a block named Scope in the Controller subsystem of the f14 system.

simulink;
open_system('f14');
add_block('simulink/Sinks/Scope', 'f14/Controller/Scope')
 

Create a subsystem named Controller2 in the f14 system. You do not have to open the Library Browser.

open_system('f14');
add_block('built-in/SubSystem', 'f14/Controller2')
 

Copy the built-in Gain block to a block named Speed in the f14 system and assign the Gain parameter a value of 4. You do not have to open the Library Browser.

open_system('f14');
add_block('built-in/Gain', 'F14/Speed', 'Gain', '4')
 

Copy the block named Mu in vdp and create a copy. Because the model already contains a Mu block, the command names the new block Mu1. Open the vdp model, which is both the source and destination model, and get the handle of the added block.

open_system('vdp');
block = add_block('vdp/Mu', 'vdp/Mu', 'MakeNameUnique', 'on')
 

Create an annotation that says "This simulates a nonlinear second order system". Position the annotation above the copyright line.

open_system('vdp');
block = add_block('built-in/Note', ...
'vdp/This simulates a nonlinear second order system', ...
'Position', [200 250])

See Also

| | |

Tutorials

Was this topic helpful?