Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

replace_block

Replace blocks in Simulink model

Syntax

replBlks = replace_block(sys,current,new)
replBlks = replace_block(sys,Name,Value,new)
replBlks = replace_block(___,'noprompt')

Description

example

replBlks = replace_block(sys,current,new) replaces the blocks current in the model sys with blocks of type new. You can use a block from a Simulink® library or from another model as the replacement block.

Load the model sys before using this function. The function prompts you to select the blocks you want to replace from a list of blocks that match the current argument.

    Tip:   Save the model before using this command.

example

replBlks = replace_block(sys,Name,Value,new) replaces the blocks that match the block parameters specified by the Name,Value pair arguments. You can also use find_system Name,Value pairs to qualify the search for blocks to replace.

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 replace_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.

To specify additional information about the search for blocks to replace, you use find_system Name,Value pairs before the block parameters. For example, you can use 'CaseSensitive','off' to make the search for blocks case insensitive or 'FollowLinks','on' to follow links into library links. See find_system for that list of Name,Value pairs.

example

replBlks = replace_block(___,'noprompt') replaces the blocks without prompting you to select them from a dialog box.

Examples

collapse all

Replace blocks in the 'vdp' model.

Load the model 'vdp'.

load_system('vdp');

Replace Gain blocks with Integrator blocks.

RepNames = replace_block('vdp','Gain','Integrator');

A dialog box prompts you to select the blocks you want to replace.

With vdp/Mu selected in the dialog box, click OK.

Replace Scope blocks with To Workspace blocks.

RepNames = replace_block('vdp','Scope','simulink/Sinks/To Workspace');

A dialog box prompts you to select the blocks you want to replace.

With vdp/Scope selected in the dialog box, click OK.

Replace blocks in the Unlocked subsystem of the sldemo_clutch model. Replace blocks whose Gain parameter is set to bv.

Load the model sldemo_clutch.

load_system('sldemo_clutch');

In the 'Unlocked' subsystem, replace blocks whose Gain value is bv with Integrator blocks.

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

A dialog box prompts you to select the blocks to replace.

With sldemo_clutch/Unlocked/VehicleDamping selected in the dialog box, click OK.

Load the model f14.

load_system('f14')

Replace Gain blocks with Integrator blocks. The command returns the blocks it found to replace and replaces the blocks.

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

  13×1 cell array

    'f14/Aircraft...'
    'f14/Aircraft...'
    'f14/Aircraft...'
    'f14/Aircraft...'
    'f14/Controller/Gain'
    'f14/Controller/Gain2'
    'f14/Controller/Gain3'
    'f14/Gain'
    'f14/Gain1'
    'f14/Gain2'
    'f14/Gain5'
    'f14/Nz pilot...'
    'f14/Nz pilot...'

Select a block that is a library link. Follow the library links and replace Gain blocks with Integrator blocks within them.

 replace_block(gcb, 'FollowLinks', 'on', 'BlockType', 'Gain', 'Integrator', 'noprompt')

Input Arguments

collapse all

Name of model whose blocks to replace, specified as a character vector. If you specify a model, the command replaces all blocks that match in the model. If you specify a subsystem, the command replaces blocks in that subsystem and below.

Example: 'vdp', 'sldemo_fuelsys/fuel_rate_control'

Type of block to replace, specified as a BlockType or MaskType value. To find out the block type, select the block and, at the command prompt, enter:

get_param(gcb,'BlockType')

For masked blocks, to find out the mask type, select the block and enter:

get_param(gcb,'MaskType')

Block to replace the current block, specified in one of these forms:

  • BlockType value of the replacement block. Specifying this value uses a library block as the replacement block.

  • MaskType value of the replacement block. Specifying this value uses a library block as the replacement block.

  • Library path of the replacement block, for example, 'simulink/Sinks/To Workspace'. Hover over the block in the library to see the library path.

  • Block path name of a block from a different model, for example, 'vdp/Mu'. Use this value to reuse an instance of a block from another model in your model.

Output Arguments

collapse all

Blocks returned by the current argument, returned as a cell array of character vectors. The function returns the values regardless of whether you complete the replacement.

Introduced before R2006a

Was this topic helpful?