Main Content

Simulink.findBlocks

Find blocks in Simulink models

Description

example

bl = Simulink.findBlocks(sys) returns handles to all blocks in the model or subsystem sys.

example

bl = Simulink.findBlocks(sys,options) finds blocks that match the criteria specified by a Simulink.FindOptions object.

example

bl = Simulink.findBlocks(sys,Param1,Value1,...,ParamN,ValueN) finds blocks whose block parameters have the specified values.

example

bl = Simulink.findBlocks(sys,Param1,Value1,...,ParamN,ValueN,options) finds blocks whose parameters have the specified values and that match the criteria specified by a FindOptions object.

Examples

collapse all

Get the handles and names of all the blocks in a model.

Open the example. Then, load the vdp model.

h=load_system('vdp')
h = 0.0017

Get the handles of all the blocks in the vdp model.

b=Simulink.findBlocks(h)
b = 12×1

    2.0262
    3.0017
    4.0017
    5.0017
    6.0017
    7.0017
    8.0017
    9.0017
   10.0017
   11.0017
      ⋮

Get the names of all the blocks in the vdp model.

names=getfullname(b)
names = 12x1 cell
    {'vdp/Callback Button'}
    {'vdp/Constant'       }
    {'vdp/Mu'             }
    {'vdp/Product'        }
    {'vdp/Scope'          }
    {'vdp/Square'         }
    {'vdp/Sum'            }
    {'vdp/Sum1'           }
    {'vdp/x1'             }
    {'vdp/x2'             }
    {'vdp/Out1'           }
    {'vdp/Out2'           }

Search for Block by Name

Open the example. Then, load the vdp model.

open_system('vdp')

Get the handle of the block named x1.

Simulink.findBlocks('vdp','Name','x1')
ans = 10.0022

Search for Blocks of Specific Type

Get the handles of all Sum blocks in the vdp model.

Simulink.findBlocks('vdp','BlockType','Sum')
ans = 2×1

    8.0022
    9.0022

Search for Blocks With Specific Parameter Value

Get the handles of all blocks in the vdp model whose Saturate On Integer Overflow parameter has the value 'on'.

Simulink.findBlocks('vdp','SaturateOnIntegerOverflow','on')
ans = 4×1

    5.0022
    7.0022
    8.0022
    9.0022

The function returns the handle of the two Sum blocks, the Product block, and the Square block in the vdp model.

Search for Blocks of Specific Type With Specific Parameter Value

Get the handles of all Sum blocks in the vdp model whose List of Signs parameter value is '+-'.

Simulink.findBlocks('vdp','ListofSigns','+-','BlockType','Sum')
ans = 9.0022

The function returns the handle of the Sum block named Sum1.

Input Arguments

collapse all

Model or subsystem to find blocks in, specified as a character vector or string array.

Example: 'vdp' "f14/Aircraft Dynamics Model"

Search constraints, specified as a Simulink.FindOptions object.

Output Arguments

collapse all

Search results, returned as an array of handles.

Version History

Introduced in R2018a