replace_block

Replace blocks in Simulink model

Syntax

replace_block('sys', 'old_blk', 'new_blk')
replace_block('sys', 'parameter', 'value', ..., 'blk')

Description

replace_block('sys', 'old_blk', 'new_blk') replaces all blocks in sys having the block or mask type old_blk with new_blk.

  • If new_blk is a Simulink® built-in block, only the block name is necessary.

  • If old_blk or new_blk is in another system, its full block pathname is required.

  • If noprompt is omitted, Simulink software displays a dialog box that asks you to select matching blocks before making the replacement. Specifying the noprompt argument suppresses the dialog box from being displayed.

  • If a return variable is specified, the paths of the replaced blocks are stored in that variable.

replace_block('sys', 'parameter', 'value', ..., 'blk') replaces all blocks in sys having the specified values for the specified parameters with blk. You can specify any number of parameter name/value pairs. You can also specify find_system parameter/value pairs followed by any number of block parameter/value pairs. For example, to replace blocks inside links, specify 'FollowLinks', 'on' to follow links into library blocks. For information on block parameters, see Block-Specific Parameters.

    Note   Because it may be difficult to undo the changes this command makes, it is a good idea to save your Simulink model first.

Examples

This command replaces all Gain blocks in the f14 system with Integrator blocks and stores the paths of the replaced blocks in RepNames. Simulink software lists the matching blocks in a dialog box before making the replacement.

RepNames = replace_block('f14','Gain','Integrator')

This command replaces all blocks in the Unlocked subsystem in the sldemo_clutch system having a Gain of 'bv' with the Integrator block. Simulink software displays a dialog box listing the matching blocks before making the replacement.

replace_block('sldemo_clutch/Unlocked','Gain','bv','Integrator')

This command replaces the Gain blocks in the f14 system with Integrator blocks but does not display the dialog box.

replace_block('f14','Gain','Integrator','noprompt')

This command replaces the Lockup Detection subsystem in the sldemo_clutch model with a Gain block.

replace_block('sldemo_clutch','Name','Lockup Detection','built-in/Gain')

This command from the mask initialization of a linked block replaces blocks inside itself:

replace_block(gcb, 'FollowLinks', 'on', 'BlockType', 'Gain', 'Integrator', 'noprompt')
Was this topic helpful?