Main Content

Simulink.findBlocksOfType

R2026b

Find specified type of block in Simulink models

Description

bl = Simulink.findBlocksOfType(sys,type) returns the handles of all blocks in the specified model or subsystem that are of the specified type.

example

bl = Simulink.findBlocksOfType(sys,type,options) matches the criteria specified by a FindOptions object.

example

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

example

bl = Simulink.findBlocksOfType(sys,type,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

Suppose you have a loaded model named myModel.

Get the handles of all Transfer Fcn blocks in the model.

h = Simulink.findBlocksOfType("myModel","TransferFcn");

Suppose you have a loaded model named myModel. The model contains a Subsystem block named mySubsystem.

Get the handles of all Transfer Fcn blocks in the subsystem.

h = Simulink.findBlocksOfType("myModel/mySubsystem","TransferFcn");

Suppose you have a loaded model named myModel. The model contains masked subsystems. Get the handles of all Transfer Fcn blocks in the model, excluding blocks in the masked subsystems.

Create a FindOptions object that specifies you want to exclude the content of masked subsystems in the search.

f = Simulink.FindOptions(SearchUnderMasks="none");

Get the block handles.

h = Simulink.findBlocksOfType("myModel","TransferFcn",f);

Suppose you have a model named myModel.

Get the handles of all Gain blocks in the model whose Gain value is 5.

h = Simulink.findBlocksOfType("myModel","Gain",Gain="5");

Input Arguments

collapse all

Model or subsystem to search for blocks. Specify a model using a name, and a subsystem using the block path of the corresponding Subsystem block. Format the name or path as a string or character vector.

For information about getting block paths, see Get Handles and Paths.

Example: "myModel"

Example: "myModel/mySubsystem"

Data Types: string | character vector

Block type, specified as a string or character vector. To get the block type, use get_param with the BlockType parameter.

Data Types: string | character vector

Search constraints, specified as a Simulink.FindOptions object.

Example: Simulink.FindOptions('SearchDepth',1)

Output Arguments

collapse all

Search results, returned as an array of handles.

Data Types: double | array of doubles

Version History

Introduced in R2018a