Simulink.FindOptions
Specify 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. Enclose
each property name in single quotes.
Properties
CaseSensitive
— Option to match case when searching
true
(default) | false
Option to match case when searching, specified as true
for case-sensitive search or false
for case-insensitive
search.
Data Types: logical
FollowLinks
— Option for search to follow library links
false
(default) | true
Option for search to follow library links, specified as
true
or false
. If
true
, search follows links into library
blocks.
Data Types: logical
IncludeCommented
— Option for search to include commented blocks
true
(default) | false
Option for search to include commented blocks, specified as
true
or false
.
Data Types: logical
LookUnderMasks
— Options to search masked blocks
'all'
(default) | 'none'
| 'functional'
| 'graphical'
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
Variants
— Options to search variant subsystems
'AllVariants'
(default) | 'ActiveVariants'
| 'ActivePlusCodeVariants'
Note
The Variants
argument will be removed. Use
MatchFilter
instead. For more information, see
Compatibility
Considerations.
Options to search variant subsystems, specified as:
'AllVariants'
— Search all variant choices.'ActiveVariants'
— Search only active variant choices.'ActivePlusCodeVariants'
— Search all variant choices in the Variant Subsystem that are active in simulation and is 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
Simulink.FindOptions
object with the
MatchFilter
option to operate on all types of
variant blocks.
Data Types: char
| string
MatchFilter
— Function handle to match elements
function handle
Function handle to match elements in a search, such as blocks, system,
lines, ports, and annotations. Use MatchFilter
to
determine whether elements should be included or skipped in a search.
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
element
is the handle of the block being processed.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 whenelement
is a subsystem. The default value isfalse
. If this value is set totrue
, the entire subsystem is omitted from the search.
Example: Use MatchFilter
to find all
Gain blocks in the model vdp
with a
gain value between 1
and 10
.
function 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
load_system('vdp'); findOptObj = Simulink.FindOptions('MatchFilter', @gainOneToTen); blks=getfullname((Simulink.findBlocks('vdp',findOptObj)));
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 compilationSimulink.match.codeCompileVariants
- Matches blocks that are part of generated code after model compilation
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.
Example: Use the Simulink.match.activeVariants
option
to find active variants in a model:
addpath(fullfile(matlabroot,'examples','simulink_variants','main')); model='sldemo_variant_subsystems'; load_system(model); assignin('base','VSS_MODE',2); set_param(model, 'SimulationCommand', 'update'); findOptObj= Simulink.FindOptions('MatchFilter', @Simulink.match.activeVariants); blks=getfullname((Simulink.findBlocks(model,findOptObj)))
Example: Use the Simulink.match.codeCompileVariants
option to find variant choices that are part of the generated C code:
addpath(fullfile(matlabroot,'examples','simulink_variants','main')); load_system('sldemo_variant_subsystems'); assignin('base','VSS_MODE',2); sldemo_variant_subsystems([], [], [], 'compileForCodegen'); findOptObj = Simulink.FindOptions('MatchFilter', @Simulink.match.codeCompileVariants); blks=getfullname((Simulink.findBlocks('sldemo_variant_subsystems',findOptObj))); sldemo_variant_subsystems([], [], [], 'term');
RegExp
— Option to treat search text as regular expression
false
(default) | true
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
SearchDepth
— Levels in model to search
-1
(default) | positive integer
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
Examples
Specify Search Options
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.
openExample('sldemo_clutch'); 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/Max↵Dynamic↵Friction↵Torque'} {'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' }
Version History
Introduced in R2018aR2021a: Variants
argument will be removed
Warns starting in R2021a
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.
To find variant blocks in a model that are active during simulation or code
generation, you can compile the model and use the
Simulink.FindOptions
object with the
MatchFilter
option.
Simulink.FindOptions
does not support the use of
MatchFilter
along with the Variants
option.
This command produces an error:
f = Simulink.FindOptions('MatchFilter',... @Simulink.match.activeVariants, 'Variants', 'ActiveVariants'); blocks=Simulink.findBlocks('sldemo_variant_subsystems',f)
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)