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

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

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

  155.0032
  278.0022
  280.0015
  283.0013
  288.0015
  291.0018
  294.0026
  298.0018
  327.0015
  330.0016
  333.0011
  335.0011
      ⋮

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

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

  301.0046
  330.0040

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

  291.0037
  298.0040
  301.0046
  330.0040

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

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