Main Content


Specify options for finding blocks in models and subsystems


Simulink.FindOptions objects allow you to constrain a search with the Simulink.findBlocks and Simulink.findBlocksOfType functions.



f = Simulink.FindOptions creates a FindOptions object that uses the default search options.


f = Simulink.FindOptions(Name,Value) sets properties using name-value pairs. For example, Simulink.FindOptions('SearchDepth',1) creates a FindOptions object with a search depth of 1. You can specify multiple name-value pairs. Enclose each property name in single quotes.


expand all

Option to match case when searching, specified as true for case-sensitive search or false for case-insensitive search.

Data Types: logical

Option for search to follow library links, specified as true or false. If true, search follows links into library blocks.

Data Types: logical

Option for search to include commented blocks, specified as true or false.

Data Types: logical

Options to search masked blocks, specified as:

  • 'all' — Search in all masked blocks.

  • 'none' — Prevent searching in masked systems.

  • 'functional' — Include masked subsystems that do not have dialogs.

  • 'graphical' — Include masked subsystems that do not have workspaces or dialogs.

Data Types: char | string

Options to search variant subsystems, specified as:

  • 'AllVariants' — Search all variant choices.

  • 'ActiveVariants' — Search only active variant choices.

  • 'ActivePlusCodeVariants' — Search all variant choices with 'Generate preprocessor conditionals' active. Otherwise, search only the active variant choices.


This search constraint applies only to variant subsystems. To work on all other variant blocks, use Variants MatchFilter option.

Data Types: char | string

A Function handle to match elements in a search, such as blocks, system, lines, ports, and annotations. Use MatchFilter to determine whether the elements should be selected or skipped in a search.

Example: Use MatchFilter to find all Gain blocks with a gain value in between 5 to 10.

blks = Simulink.FindOptions('ModelName', 'MatchFilter', @gainFiveToTen)
function match = gainFiveToTen(el)
match = false;

if strcmp(get_param(el,'Type'),'block') ...
     && strcmp(get_param(el,'BlockType'),'Gain')
     gainValue = str2double(get_param(el, 'Gain'));
     match = gainValue >= 5 && gainValue <= 10;

This example shows how to use MatchFilter with second output argument prune.

 [match, prune] = fcn(element)
  element - Handle of the block being processed.
  match   - Logical. If false, skip the element.
  prune   - Optional logical (default false). If true, do not look in subsystems.

Variants: Simulink provides Simulink.match.activeVariants and Simulink.match.codeCompileVariants match filter functions for variant blocks, which you can use to find active variants or code compile variant blocks. To do so, compile the model and apply the appropriate MatchFilter options:

  • Simulink.match.activeVariants - Matches blocks that are active in simulation after model compilation

  • Simulink.match.codeCompileVariants - Matches blocks that are part of generated code after model compilation

Example: Use the Simulink.match.activeVariants option to find active variants in a model:

set_param(model, 'SimulationCommand', 'update');
activeBlks = simulink.FindOptions(model, 'MatchFilter', @Simulink.match.activeVariants);

Example: Use the Simulink.match.codeCompileVariants option to find variant choices that are part of the generated C code:

 F = Simulink.FindOptions('MatchFilter', @Simulink.match.codeCompileVariants);
 Simulink.findBlocks(SYSTEM, F);

Option to treat search text as a regular expression, specified as true or false. To learn more about MATLAB® regular expressions, see Regular Expressions.

Data Types: logical

Levels in model to search, specified as a positive integer. The default (-1) is to search all levels. Specify:

  • 1 — Search in the top-level system.

  • 2 — Search the top-level system and its children, 3 to search an additional level, and so on.

Data Types: int32


collapse all

Create a Simulink.FindOptions object that specifies a search depth of 1.

f = Simulink.FindOptions('SearchDepth',1);

Using the FindOptions object, search for all blocks in the subsystem named Unlocked, but not in any of its children.

bh = Simulink.findBlocks('sldemo_clutch/Unlocked',f);

The Simulink.findBlocks function returns the block handles.

To get the block path, use the getfullname function.

bp = getfullname(bh)
bp =

  20×1 cell array

    {'sldemo_clutch/Unlocked/Tfmaxk'                     }
    {'sldemo_clutch/Unlocked/Tin'                        }
    {'sldemo_clutch/Unlocked/Enable'                     }
    {'sldemo_clutch/Unlocked/E_Sum'                      }
    {'sldemo_clutch/Unlocked/Engine↵Damping'             }
    {'sldemo_clutch/Unlocked/Engine↵Inertia'             }
    {'sldemo_clutch/Unlocked/Engine↵Integrator'          }
    {'sldemo_clutch/Unlocked/Goto'                       }
    {'sldemo_clutch/Unlocked/Goto1'                      }
    {'sldemo_clutch/Unlocked/V_Sum'                      }
    {'sldemo_clutch/Unlocked/Vehicle↵Damping'            }
    {'sldemo_clutch/Unlocked/Vehicle↵Inertia'            }
    {'sldemo_clutch/Unlocked/Vehicle↵Integrator'         }
    {'sldemo_clutch/Unlocked/W_Slip'                     }
    {'sldemo_clutch/Unlocked/slip direction'             }
    {'sldemo_clutch/Unlocked/w0'                         }
    {'sldemo_clutch/Unlocked/w0 '                        }
    {'sldemo_clutch/Unlocked/we'                         }
    {'sldemo_clutch/Unlocked/wv'                         }
Introduced in R2018a