Main Content

Simulink.findBlocks

R2026b

Find blocks in Simulink models

Description

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

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

Suppose you have a model named myModel. Get the handles and names of all blocks in the model.

Get the handles of all blocks in the model.

h = Simulink.findBlocks("myModel");

Get the block names.

n = getfullname(h);

Suppose you have a model named myModel. The model contains a Subsystem block named mySubsystem. Get the handles and names of all blocks in the subsystem.

Get the handles of all blocks in the model.

h = Simulink.findBlocks("myModel/mySubsystem");

Suppose you have a loaded model named myModel. The model contains masked subsystems. Get the handles of all 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.findBlocks("myModel",f);

Suppose you have a model named myModel.

Get the handles of all blocks in the model whose Gain parameter has a value of 5.

h = Simulink.findBlocks("myModel",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

Search constraints, specified as a Simulink.FindOptions object.

Output Arguments

collapse all

Search results, returned as an array of handles.

Data Types: double | array of doubles

Version History

Introduced in R2018a