Main Content

Simulink.findBlocks

Find blocks in Simulink models

Description

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.

example

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

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

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

  154.0056
  277.0044
  279.0042
  282.0044
  286.0048
  314.0101
  317.0093
  321.0060
  326.0052
  352.0040
      ⋮

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 = 
186.0006

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

  178.0009
  182.0006

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

  167.0004
  175.0005
  178.0009
  182.0006

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 = 
182.0006

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