Simulink.FindOptions
R2026bSpecify options for finding blocks in models and subsystems
Description
Simulink.FindOptions objects allow you to constrain a search
with the Simulink.findBlocks and
Simulink.findBlocksOfType functions.
Creation
Description
creates a
f = Simulink.FindOptionsFindOptions object that uses the default search
options.
sets properties using name-value pairs. For example,
f = Simulink.FindOptions(Name=Value)Simulink.FindOptions(SearchDepth=1) creates a
FindOptions object with a search depth of
1. You can specify multiple name-value pairs.
Properties
Option to consider case when matching. To turn the option on, specify
true. To turn the option off, specify
false.
Data Types: logical
Option to look inside referenced subsystems in a model and list child
blocks. To turn the option on, specify true. To turn the
option off, specify false.
Data Types: logical
Option to search inside referenced models in a model and list child
blocks. To turn the option on, specify true. To turn the
option off, specify false.
Data Types: logical
Option to search inside library links. To turn the option on, specify
true. To turn the option off, specify
false.
If you do not specify a model to search, the
find_system function includes loaded libraries in
the results regardless of whether specify true or
false. You can use
SearchInsideLibraryLinks with
SearchUnderMasks to update library links in
subsystems. See Update Library Links in a Subsystem.
Data Types: logical
Option to include commented blocks in the search. To turn the option on,
specify true. To turn the option off, specify
false.
Data Types: logical
Option to load any partially loaded models. To turn the option on, specify
true. To turn the option off, specify
false. Use this option, for example, to prevent load
warnings.
Data Types: logical
Options for searching under masks, specified as one of these values:
"none"— Search skips masked subsystems."all"— Search includes all masked subsystems."functional"— Search includes masked subsystems that has icon drawing commands or mask initialization commands without having parameters, description, help strings, and UI elements."graphical"— Search includes masked subsystems that has only icon drawing commands without having workspaces, dialogs, help strings, and UI elements.
Data Types: string | char
Option to treat search expressions as regular expressions. To turn the
option on, specify true. To turn the option off, specify
false.
When you turn the option on, the search treats search expressions as regular expressions. To learn more about MATLAB® regular expressions, see Regular Expressions.
Data Types: logical
Option to restrict the search depth to the specified level, specified as a positive integer. Format the value as a numeric scalar, string, or character vector.
For example, specify 0 to search loaded models only,
1 for blocks and subsystems of the top level of the
model hierarchy, 2 for the top level of the model
hierarchy and its children, etc. The default value -1 is
to search all levels.
Data Types: int32
Note
The Variants argument will be removed. Use
MatchFilter instead. For more information, see
Version History.
Options for searching variants, specified as one of these options:
"ActiveVariants"— Search only the active variant choice in the Variant Subsystem."AllVariants"— Search all variant choices in the Variant Subsystem."ActivePlusCodeVariants"— Search all variant choices in the Variant Subsystem that are active in simulation and are part of the generated code.
This search constraint applies only to Variant Subsystem
blocks that have the Variant control mode set to
expression or label. Use the
find_system function with the
MatchFilter option to operate on all types of
variant blocks.
Data Types: string | char
Option to match and filter elements such as blocks, model, lines, ports,
and annotations in a search, specified as function handle. Use
MatchFilter to determine whether elements should be
included or skipped in a search.
The argument:
Allows you to filter elements with custom filter functions
Avoids processing elements when filters do not match
Applies complex filters on blocks, lines, or annotations, to filter the results internally
The named function must be defined within a MATLAB program file. The function takes the handle of the element as input and returns two outputs.
function [match, prune] = func(element)
The input
elementis the handle of the component being processed, for example the block handle.The first output,
match, is a logical value. Iffalse, search skips the element.The second output,
prune, is an optional logical value that only applies whenelementis a subsystem. The default value isfalse. If this value is set totrue, the entire subsystem is omitted from the search.
Variants: Simulink® provides these built-in match filter functions to find variant blocks.
Post-compile time filter functions:
Simulink.match.activeVariants— Filter function to find blocks that are active in simulation after model compilation.Simulink.match.codeCompileVariants— Filter function to find blocks that are part of generated code after model compilation.Simulink.match.allVariants— Filter function to find all blocks irrespective of whether the block is active or inactive due to variants.
Note
To get correct results, you must compile the
model before using
Simulink.match.activeVariants and
Simulink.match.codeCompileVariants filters.
If the model is not compiled, these filters return all blocks in the
model.
For an example that compares the pre-compile and post-compile time results for these filters, see Compare Pre-Compile and Post-Compile Behavior of Match Filters for Variant Blocks.
Edit-time filter functions for Variant Subsystem blocks:
Simulink.match.legacy.filterOutCodeInactiveVariantSubsystemChoices— Include in the search the blocks inside the choices of a variant subsystem that are active in simulation and are part of the generated code. This function produces similar results as the'ActivePlusCodeVariants'option of theVariantsargument.Simulink.match.legacy.filterOutInactiveVariantSubsystemChoices— Include in the search the blocks inside the active choice of a variant subsystem. This function produces similar results as the'ActiveVariants'option of theVariantsargument.
Limitations of edit-time filters:
The filters do not use the post-compile block activeness information in the CompiledVariantInfo block parameter.
The filters apply only to Variant Subsystem blocks that have these block parameter settings:
Variant control mode set to
expressionorlabelPropagate conditions outside of variant subsystem set to
off
The filters can identify if a block handle is inside the active choice of a Variant Subsystem only when used within the context of
find_system,find_mdlrefs, andSimulink.FindOptions.
To operate on all types of variant blocks, use the
Simulink.match.codeCompileVariants or
Simulink.match.activeVariants filters after model
compilation.
Examples
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 loaded model named
myModel. The model contains subsystems and other
components. Get the handles of all Transfer Fcn blocks in the top
level of the model.
Get the model handle.
hModel = get_param("myModel","Handle");
Create a FindOptions object that specifies you want to
exclude the content of masked subsystems in the search.
f = Simulink.FindOptions(SearchDepth=1);
Get the block handles.
h = Simulink.findBlocks(hModel,f);
You can use the MatchFilter argument to specify which elements to include in the search, as defined by a custom filter function.
For example, to find all Gain blocks in a model with a gain value between 1 and 10, define a custom filter function as shown in the file gainOneToTen.m. This function checks each block and returns true only for Gain blocks whose gain value is within the specified range.
type gainOneToTen.mfunction match = gainOneToTen(blk)
match = false;
if strcmp(get_param(blk,'Type'),'block') ...
&& strcmp(get_param(blk,'BlockType'),'Gain')
gainValue = str2double(get_param(blk, 'Gain'));
match = gainValue >= 1 && gainValue <= 10;
end
end
To apply this filter to the slexVariantSourceAndSink model, provide the function handle as the value for the MatchFilter argument in the Simulink.FindOptions object. Then, use the object with the Simulink.findBlocks function.
load_system("slexVariantSourceAndSink"); findOptObj = Simulink.FindOptions("MatchFilter",@gainOneToTen); blks = getfullname((Simulink.findBlocks("slexVariantSourceAndSink",findOptObj)))
blks = 4×1 cell
{'slexVariantSourceAndSink/Gain2'}
{'slexVariantSourceAndSink/Gain3'}
{'slexVariantSourceAndSink/Gain4'}
{'slexVariantSourceAndSink/Gain5'}
Load the slexVariantSubsystems model.
model = 'slexVariantSubsystems'; load_system(model); assignin('base','VSS_MODE',2);
Use the MatchFilter option with Simulink.match.activeVariants to find blocks that are active in simulation after model compilation.
set_param(model,'SimulationCommand','update'); findOptObj = Simulink.FindOptions('MatchFilter',@Simulink.match.activeVariants); blks = getfullname((Simulink.findBlocks(model,findOptObj)));
Use the MatchFilter option with Simulink.match.codeCompileVariants to find blocks that are part of the generated C code after model compilation.
slexVariantSubsystems([],[],[],'compileForCodegen'); findOptObj = Simulink.FindOptions('MatchFilter',@Simulink.match.codeCompileVariants); blks = getfullname((Simulink.findBlocks(model,findOptObj))); slexVariantSubsystems([],[],[],'term');
Use the MatchFilter option with Simulink.match.allVariants to find all blocks in a model.
findOptObj = Simulink.FindOptions('MatchFilter',@Simulink.match.allVariants);
blks = getfullname((Simulink.findBlocks(model,findOptObj)));Use the edit-time filter function Simulink.match.legacy.filterOutCodeInactiveVariantSubsystemChoices to include in the search the blocks inside the choices of a variant subsystem that are active in simulation and are part of the generated code. For information on the limitations of edit-time filters, see MatchFilter.
findOptObj = Simulink.FindOptions('MatchFilter',@Simulink.match.legacy.filterOutCodeInactiveVariantSubsystemChoices);
blks = getfullname((Simulink.findBlocks(model,findOptObj)));Use the edit-time filter function Simulink.match.legacy.filterOutInactiveVariantSubsystemChoices to include in the search the blocks inside the active choice of a variant subsystem. For information on the limitations of edit-time filters, see MatchFilter.
findOptObj = Simulink.FindOptions('MatchFilter',@Simulink.match.legacy.filterOutInactiveVariantSubsystemChoices);
blks = getfullname((Simulink.findBlocks(model,findOptObj)));Find the Variant Subsystem blocks in the model.
findOpts = Simulink.FindOptions('MatchFilter',@Simulink.match.legacy.filterOutInactiveVariantSubsystemChoices); blksVSS = getfullname((Simulink.findBlocks(model,'BlockType','SubSystem','Variant','on',findOpts)));
Version History
Introduced in R2018aTo enable search under blocks in a model and references, set the
LookUnderModelBlocks property to
true.
Several properties have been renamed:
LookUnderModelBlockshas been renamed toSearchInsideModelReferences.LookInsideSubsystemReferencehas been renamed toSearchInsideSubsystemReferences.LookUnderMaskshas been renamed toSearchUnderMasks.FollowLinkshas been renamed toSearchInsideLibraryLinks.
The previous names continue to work.
You can use the built-in match filter,
Simulink.match.allVariants, to find all the blocks in a
variant model regardless of whether the block is active or inactive due to variants.
This filter is the recommended replacement for the AllVariants
option.
| To be removed | Recommended Replacement |
|---|---|
findOptObj= Simulink.FindOptions('Variants', ... 'AllVariants'); |
findOptObj= Simulink.FindOptions('MatchFilter', ... @Simulink.match.allVariants); |
The Variants option will be removed from
Simulink.FindOptions in a future release. Scripts that use the
Variants option continue to work with a warning.
Using the Simulink.FindOptions object with the
Variants argument produces inconsistent search results.
Simulink.FindOptions is used at edit-time, but to determine
whether a block is active in a model with all types of variant blocks, you need to
compile the model.
To find variant blocks that are active during simulation or code generation,
compile the model and use the Simulink.FindOptions object with the
MatchFilter option.
This table lists the recommended replacement for different values of the
Variants option.
| To Be Removed | Recommended Replacement |
|---|---|
findOptObj= Simulink.FindOptions('Variants', ... 'ActiveVariants'); |
set_param(model,'SimulationCommand','update'); findOptObj= Simulink.FindOptions('MatchFilter', ... @Simulink.match.activeVariants); |
findOptObj= Simulink.FindOptions('Variants', ... 'ActivePlusCodeVariants'); |
model([], [], [], 'compileForCodegen'); findOptObj = Simulink.FindOptions('MatchFilter', ... @Simulink.match.codeCompileVariants); blks=getfullname((Simulink.findBlocks(model,findOptObj))); model([], [], [], 'term'); |
When you use the Simulink.FindOptions object, you cannot specify
both of the MatchFilter and Variants
arguments.
This command produces an error.
f = Simulink.FindOptions('MatchFilter',... @Simulink.match.activeVariants, 'Variants', 'ActiveVariants'); blocks=Simulink.findBlocks('sldemo_variant_subsystems',f)
To match and filter model elements during a search, you can define a custom filter
function and pass the function handle as value to the
MatchFilter option.
To find variant blocks that are active in a simulation or part of the generated
code, you can use the built-in match filter functions,
Simulink.match.activeVariants,
Simulink.match.codeCompileVariants, and
Simulink.match.allVariants, after compiling the model.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)