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

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

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

  279.0020
  280.0018
  308.0018
  311.0015
  316.0013
  319.0011
  322.0013
  326.0012
  330.0010
  333.0010
  336.0015
  338.0010
      ⋮

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

names=getfullname(b)
names = 12×1 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 = 
330.0599

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

  322.0734
  326.0626

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

  311.0713
  319.1010
  322.0734
  326.0626

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

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