Main Content

delete_block

Delete blocks from Simulink system

Description

delete_block(blockArg) deletes the specified blocks from a system. Open the system before you delete blocks.

example

Examples

collapse all

You can programmatically delete a block from the library using the delete_block function with one of these input arguments:

  • Full block path including block name, for example, 'myModel/mySubsystem/myblock'

  • Block handle

This example shows how to programmatically delete blocks using the full block path.

Delete One Block

Delete the pitch rate filter from the f14 model.

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

open_system('f14')

Suppose you do not know the exact name of the block needed to complete this task or the location of the block in the model.

Get the full block paths of all blocks in the f14 model using the find_system function.

Paths=find_system('f14','Type','Block');

Narrow the results down to the paths that contain the word filter or Filter.

FilterPaths=Paths(contains(Paths,{sprintf('Filter'),sprintf('filter')}));
disp(FilterPaths)
    {'f14/Controller/Alpha-sensor...'}
    {'f14/Controller/Pitch Rate...'  }
    {'f14/Controller/Stick...'       }

When you specify a multiline full block path, specify the transition to a new line with a space. The full block path of the pitch rate filter is 'f14/Controller/Pitch Rate Lead Filter'.

Delete the block using the full block path.

delete_block('f14/Controller/Pitch Rate Lead Filter')

To verify that the block is deleted, open the Controller subsystem.

open_system('f14/Controller')

Delete Multiple Blocks

Delete the other two filter blocks.

delete_block({'f14/Controller/Alpha-sensor Low-pass Filter','f14/Controller/Stick Prefilter'})

You can programmatically delete a block from the library using the delete_block function with one of these input arguments:

  • Full block path including block name, for example, 'myModel/mySubsystem/myblock'

  • Block handle

This example shows how to programmatically delete blocks using the block handle.

Delete One Block

Delete the pitch rate filter from the f14 model.

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

open_system('f14')

Get the handle of the Transfer Function block named Pitch Rate Lead Filter in the Controller subsystem.

h=getSimulinkBlockHandle('f14/Controller/Pitch Rate Lead Filter')
h = 
397.0020

Delete the block using the handle.

delete_block(h)

To verify that the block is deleted, open the Controller subsystem.

open_system('f14/Controller')

Delete Multiple Blocks

Get the handles of the Transfer Function blocks named Alpha-sensor Low-pass Filter and Stick Prefilter in the Controller subsystem.

h1=getSimulinkBlockHandle('f14/Controller/Alpha-sensor Low-pass Filter');
h2=getSimulinkBlockHandle('f14/Controller/Stick Prefilter');

Delete the other two filter blocks.

delete_block([h1, h2])

Input Arguments

collapse all

Blocks to delete, specified as the full block path name, a handle, a vector of handles, or a 1-D cell array or string array of handles or block path names.

Example: 'vdp/Mu'

Example: [handle1 handle2]

Example: {'vdp/Mu' 'vdp/Out1' 'vdp/Out2'}

Example: "vdp/Out"+(1:2)

Version History

Introduced before R2006a

See Also