slreportgen.finder.BlockFinder class

Package: slreportgen.finder

Find Simulink blocks


Finds blocks in a Simulink® diagram.


finder = BlockFinder(diagram) creates a finder that finds by default all types of blocks in the specified Simulink block diagram. To constrain the search to specific types of blocks, use the properties of the finder.


This finder provides two ways to get search results:

  1. To return the search results as an array, use the find method. Add the results directly to a report or process the results in a for loop.

  2. To iterate through the results one at a time, use the hasNext and next methods in a while loop.

Neither option has a performance advantage.

finder = BlockFinder(Name,Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order. Enclose each property name in single quotes.

Input Arguments

expand all

See Container property.


expand all

Diagram in which to search, specified as one of these values:

  • Handle to a Simulink model or subsystem

  • Path to a Simulink model or subsystem

Type of block to find, such as Gain, specified as a string or character array, or a set of block types to find, specified as a string array or a cell array of character arrays.

Whether to include commented-out blocks in the search results, specified as a logical. If false, commented-out blocks are excluded from the search results.

Variants of a variant block to include in the search results, specified as one of the values in the table. You can specify the value as a string scalar or a character vector.

"Active"Active variants (default)
"All"All variants
"ActivePlusCode"Active variants and code variants

Properties of objects to find, specified as a cell array of name-value pairs. The finder returns only objects that have the specified properties with the specified values.

Example: finder.Properties = {'Gain','5'}


results = find(finder) finds blocks in the diagram specified by the finder. This method returns the blocks it finds wrapped in result objects of type slreportgen.finder.BlockResult. To add tables of the block properties, add the results objects directly to the report or add them to a reporter that you then add to a report. The reports to which you can add the results of this method must be of reports of type

tf = hasNext(finder) determines if the diagram that the finder searches contains at least one block. If the diagram has at least one block, the hasNext method queues that block as the next block that the next method will return. The hasNext method then returns true. Use the next method to obtain that block. On subsequent calls, the hasNext method determines if the diagram has a block that the next method has not yet retrieved. It queues the block for the next method to retrieve and returns true. If there are no more blocks to be retrieved, this method returns false. To search a diagram progressively for blocks, use the hasNext method with the next method in a while loop.

result = next(finder) returns the next search result in the result queue that the hasNext method created. This method returns the block that it finds wrapped in a result object of type slreportgen.finder.BlockResult. To add tables of the block properties, add the result object to the report directly or add it to a reporter that you then add to a report. The reports to which you can add the results of this method must be of type

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).


Find Inport and Outport Blocks in a Model

Find Inport and Output blocks in the sf_car model.

import slreportgen.finder.*

model_name = 'sf_car';
rpt ='output','pdf');

     sprintf('I/O Blocks in %s Model',model_name)));

diagFinder = SystemDiagramFinder(model_name);
diagFinder.IncludeRoot = false;
while hasNext(diagFinder)
    diagram = next(diagFinder);
    chapter = Chapter("Title",diagram.Name);
    sect = Section("Title","Inport Blocks");
    ioFinder = BlockFinder(diagram.Object);
    ioFinder.BlockTypes = "Inport";
    blocks = find(ioFinder);
    for block = blocks
    sect = Section("Title","Outport Blocks");
    ioFinder = BlockFinder(diagram.Object);
    ioFinder.BlockTypes = "Outport";
    outblocks = find(ioFinder);
    for block = outblocks

Introduced in R2017b