find_system - Find models, blocks, lines, ports, and annotations - MATLAB (original) (raw)
Find models, blocks, lines, ports, and annotations
Syntax
Description
[Objects](#f21-23425-Objects) = find_system
returns loaded models and their blocks, including subsystems.
[Objects](#f21-23425-Objects) = find_system([Model](#f21-23425-System))
returns the specified model and its blocks.
[Objects](#f21-23425-Objects) = find_system([Name,Value](#namevaluepairarguments))
returns loaded models and the objects in those models that meet the criteria specified by one or more Name,Value
pair arguments. You can use this syntax to specify search constraints and to search for specific parameter values. Specify the search constraints before the parameter and value pairs.
[Objects](#f21-23425-Objects) = find_system([Model](#f21-23425-System),[Name,Value](#namevaluepairarguments))
returns the objects in the specified model that meet the specified criteria.
Examples
Open the example. Then, load the vdp
model.
Find all loaded models and libraries and their blocks.
ans = 13×1 cell {'vdp' } {'vdp/Callback Button'} {'vdp/Constant' } {'vdp/Mu' } {'vdp/Product' } {'vdp/Scope' } {'vdp/Square' } {'vdp/Sum' } {'vdp/Sum1' } {'vdp/x1' } {'vdp/x2' } {'vdp/Out1' } {'vdp/Out2' }
Open the example. Then, load the vdp
and ex_sldemo_clutch
models.
load_system({'vdp','ex_sldemo_clutch'})
Find the vdp
model and its blocks.
ans = 13×1 cell {'vdp' } {'vdp/Callback Button'} {'vdp/Constant' } {'vdp/Mu' } {'vdp/Product' } {'vdp/Scope' } {'vdp/Square' } {'vdp/Sum' } {'vdp/Sum1' } {'vdp/x1' } {'vdp/x2' } {'vdp/Out1' } {'vdp/Out2' }
Open the example. Then, load the vdp
model.
Find all loaded models, subsystems, and libraries. A subsystem name is returned only if the subsystem can be loaded independently.
find_system('type','block_diagram')
ans = 1×1 cell array {'vdp'}
Open the example. Then, load the ex_sldemo_clutch
model.
load_system('ex_sldemo_clutch')
Return the names of all Goto blocks that are children of the Unlocked
subsystem in the ex_sldemo_clutch
model.
find_system('ex_sldemo_clutch/Unlocked','SearchDepth',1,'BlockType','Goto')
ans = 2×1 cell {'ex_sldemo_clutch/Unlocked/Goto' } {'ex_sldemo_clutch/Unlocked/Goto1'}
Open the example. Then, load the vdp
model.
Find blocks in the vdp
model that meet these two criteria.
- The block is an Integrator block.
- The value of Initial condition is 0.
find_system('vdp','BlockType','Integrator','InitialCondition','0')
ans = 1×1 cell array {'vdp/x2'}
Open the example. Then, load the vdp
model.
Find the lines in the vdp
model using the find_system
function. To include lines in the search, specify 'FindAll'
as 'on'
.
l = find_system('vdp','FindAll','on','type','line')
l = 20×1
363.0094 362.0090 361.0088 360.0087 359.0073 358.0084 357.0110 356.0096 355.0095 354.0084 353.0089 352.0072 351.0084 350.0099 349.0087 ⋮
Find the annotations in the vdp
model using the find_system
function. To include annotations in the search, specify 'FindAll'
as 'on'
.
an = find_system('vdp','FindAll','on','type','annotation')
an = 3×1
366.0088 365.0090 364.0096
Open the example. Then, load the vdp
and f14
models.
models={'vdp','f14'}; load_system(models)
Find any blocks with Block Dialog
box parameters whose value is 3
in the vdp
and f14
models.
find_system(models,'BlockDialogParams','3')
ans = 3×1 cell {'vdp/Square' } {'f14/Aircraft↵Dynamics↵Model/Rotary Gust↵qGust (rad//sec)'} {'f14/Controller/q (rad//sec)' }
Open the example. Then, load the ex_sldemo_clutch
and vdp
models.
load_system({'ex_sldemo_clutch','vdp'})
Find all blocks in the top level of the currently loaded models with a Block Parameters dialog box parameter value that starts with 3
.
find_system('SearchDepth','1','regexp','on','BlockDialogParams','^3')
ans = 4×1 cell {'vdp/Scope' } {'vdp/Scope' } {'vdp/Square' } {'ex_sldemo_clutch/w'}
When you search using regular expressions, you can specify a part of the character vector you want to match to return all objects that contain that character vector.
Find all the Integrator blocks in the ex_sldemo_clutch
model.
load_system('ex_sldemo_clutch'); ports=find_system('ex_sldemo_clutch','regexp','on','blocktype','Integrator')
ports = 3×1 cell {'ex_sldemo_clutch/Locked/Engine//Vehicle↵Integrator'} {'ex_sldemo_clutch/Unlocked/Engine↵Integrator' } {'ex_sldemo_clutch/Unlocked/Vehicle↵Integrator' }
Suppose you have a model named myModel
that contains a single subsystem, which is a library link. After the model was last opened, a Gain block was added to the corresponding subsystem in the library.
Open the model. Use find_system
with'FollowLinks'
set to 'off'
. The command does not follow the library links into the subsystem and returns only the subsystem at the top level.
open_system('myModel') find_system(bdroot,'LookUnderMasks','all','FollowLinks', 'off')
ans =
'myModel'
'myModel/Subsystem'
Use find_system
with 'FollowLinks'
set to 'on'
. find_system
updates the library links and returns the block in the subsystem.
find_system(bdroot,'LookUnderMasks','all','FollowLinks','on')
Updating Link: myModel/Subsystem/Gain Updating Link: myModel/Subsystem/Gain
ans =
'myModel'
'myModel/Subsystem'
'myModel/Subsystem/Gain'
When you make multiple function calls that require you to specify the model or block the function acts on, use handles instead of file paths to specify the model or block.
Specify the vdp model
as a handle in multiple calls to the find_system
function.
Open the example. Then, load the vdp
model.
Get the handle of the vdp
model.
h = get_param('vdp','Handle')
Find Block Parameters dialog box parameters in the vdp
model with a value of 0
. Specify the model to search as the handle of the vdp
model.
find_system(h,'BlockDialogParams','0')
ans = 8×1
288.0096 288.0096 295.0095 337.0095 340.0074 340.0074 342.0079 342.0079
Find block parameters in the vdp
model with a Block Parameters dialog box parameter value that starts with 3
. Specify the model to search as the handle of the vdp
model.
find_system(h,'regexp','on','BlockDialogParams','^3')
ans = 3×1
295.0095 295.0095 298.0115
Find blocks in the vdp
model whose block name contains the character vector 'port'
. Specify the model to search as the handle of the vdp
model.
find_system(h,'regexp','on','blocktype','port')
ans = 2×1
340.0074 342.0079
Use the MatchFilter argument with a custom filter function to find blocks other than Inport and Outport blocks in the vdp
model.
The custom function for this example is defined in the file nonInOutBlocks.m
.
function match = nonInOutBlocks(handle) match = true; if strcmp(get_param(handle,'Type'),'block') blockType = get_param(handle,'BlockType'); if strcmp(blockType,'Inport') || strcmp(blockType,'Outport') match = false; end end end
Provide the function handle as the value of the MatchFilter
argument.
load_system('vdp'); blks = find_system('vdp','MatchFilter',@nonInOutBlocks);
Simulink® provides built-in functions that you can use to find variant blocks in a model. For more information, see MatchFilter.
Load the slexVariantSubsystems
model.
model = 'slexVariantSubsystems'; load_system(model); assignin('base','VSS_MODE',2);
Use the Simulink.match.activeVariants
function to find variant blocks that are active in simulation after model compilation.
set_param(model,'SimulationCommand','update'); find_system(model,'MatchFilter',@Simulink.match.activeVariants);
Use the Simulink.match.codeCompileVariants
function to find variant choices that are part of the generated C code after model compilation.
slexVariantSubsystems([],[],[],'compileForCodegen'); find_system(model,'MatchFilter',@Simulink.match.codeCompileVariants); slexVariantSubsystems([],[],[],'term');
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.
Use the Simulink.match.allVariants
function to find all blocks irrespective of whether the block is active or inactive due to variants.
find_system(model,'MatchFilter',@Simulink.match.allVariants);
Use the Simulink.match.legacy.filterOutCodeInactiveVariantSubsystemChoices
function to find Variant Subsystem choice blocks that are active in simulation or part of generated code at edit-time. For information on the limitations of edit-time filters, see MatchFilter.
find_system(model, ... 'MatchFilter',@Simulink.match.legacy.filterOutCodeInactiveVariantSubsystemChoices);
Use the Simulink.match.legacy.filterOutInactiveVariantSubsystemChoices
function to find active Variant Subsystem choice blocks at edit-time. For information on the limitations of edit-time filters, see MatchFilter.
find_system(model, ... 'MatchFilter', @Simulink.match.legacy.filterOutInactiveVariantSubsystemChoices);
Use the Simulink.match.variantAssemblySubsystems
function to find all Variant Assembly Subsystem blocks in the slexVariantAssemblySubsystemWithMaskInLabel
model.
load_system('slexVariantAssemblySubsystemWithMaskInLabel'); find_system('slexVariantAssemblySubsystemWithMaskInLabel','MatchFilter',@Simulink.match.variantAssemblySubsystems);
This example compares the pre-compile and post-compile results for the built-in find_system
MatchFilter functions to find variant blocks. These filters help to find variant blocks that are active in simulation or part of the generated code:
Simulink.match.activeVariants
Simulink.match.codeCompileVariants
- Open the model slexVariantSubsystems. The model is configured to generate code using Embedded Coder® and uses an ERT-based system target file,
ert.tlc
.
model="slexVariantSubsystems"; open_system(model);
2. Set the VariantActivationTime
parameter of the Controller block to code compile
. For this activation time, the code generated using Embedded Coder includes both the active and inactive variant choices.
set_param('slexVariantSubsystems/Controller','VariantActivationTime','code compile');
3. Set the TreatAsAtomicUnit
parameter to on
for the choices of the Controller block. This step is needed to use code compile
activation time for the Controller block.
set_param('slexVariantSubsystems/Controller/Linear Controller', 'TreatAsAtomicUnit', 'on'); set_param('slexVariantSubsystems/Controller/Nonlinear Controller', 'TreatAsAtomicUnit', 'on');
find_system
Results Before Model Compilation
Using the built-in match filters before compiling the model returns all blocks in the model, irrespective of their variant activeness.
find_system(model,MatchFilter=@Simulink.match.activeVariants)
ans = 25×1 cell {'slexVariantSubsystems' } {'slexVariantSubsystems/Controller' } {'slexVariantSubsystems/Controller/sensor1' } {'slexVariantSubsystems/Controller/sensor2' } {'slexVariantSubsystems/Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller' } {'slexVariantSubsystems/Controller/Linear Controller/sensor1' } {'slexVariantSubsystems/Controller/Linear Controller/sensor2' } {'slexVariantSubsystems/Controller/Linear Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller/Add' } {'slexVariantSubsystems/Controller/Linear Controller/Discrete↵Transfer Fcn'} {'slexVariantSubsystems/Controller/Linear Controller/Out1' } {'slexVariantSubsystems/Controller/Nonlinear Controller' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor1' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor2' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor3' } {'slexVariantSubsystems/Controller/Nonlinear Controller/1-D Lookup Table' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Add' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Out1' } {'slexVariantSubsystems/Controller/Out1' } {'slexVariantSubsystems/Scope' } {'slexVariantSubsystems/sine1' } {'slexVariantSubsystems/sine2' } {'slexVariantSubsystems/sine3' } {'slexVariantSubsystems/Out1' }
find_system(model,MatchFilter=@Simulink.match.codeCompileVariants)
ans = 25×1 cell {'slexVariantSubsystems' } {'slexVariantSubsystems/Controller' } {'slexVariantSubsystems/Controller/sensor1' } {'slexVariantSubsystems/Controller/sensor2' } {'slexVariantSubsystems/Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller' } {'slexVariantSubsystems/Controller/Linear Controller/sensor1' } {'slexVariantSubsystems/Controller/Linear Controller/sensor2' } {'slexVariantSubsystems/Controller/Linear Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller/Add' } {'slexVariantSubsystems/Controller/Linear Controller/Discrete↵Transfer Fcn'} {'slexVariantSubsystems/Controller/Linear Controller/Out1' } {'slexVariantSubsystems/Controller/Nonlinear Controller' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor1' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor2' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor3' } {'slexVariantSubsystems/Controller/Nonlinear Controller/1-D Lookup Table' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Add' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Out1' } {'slexVariantSubsystems/Controller/Out1' } {'slexVariantSubsystems/Scope' } {'slexVariantSubsystems/sine1' } {'slexVariantSubsystems/sine2' } {'slexVariantSubsystems/sine3' } {'slexVariantSubsystems/Out1' }
find_system
Results After Model Compilation
Compile the model.
set_param(model,"SimulationCommand","update");
Using the Simulink.match.activeVariants
filter returns the blocks that are active in simulation.
find_system(model,MatchFilter=@Simulink.match.activeVariants)
ans = 18×1 cell {'slexVariantSubsystems' } {'slexVariantSubsystems/Controller' } {'slexVariantSubsystems/Controller/sensor1' } {'slexVariantSubsystems/Controller/sensor2' } {'slexVariantSubsystems/Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller' } {'slexVariantSubsystems/Controller/Linear Controller/sensor1' } {'slexVariantSubsystems/Controller/Linear Controller/sensor2' } {'slexVariantSubsystems/Controller/Linear Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller/Add' } {'slexVariantSubsystems/Controller/Linear Controller/Discrete↵Transfer Fcn'} {'slexVariantSubsystems/Controller/Linear Controller/Out1' } {'slexVariantSubsystems/Controller/Out1' } {'slexVariantSubsystems/Scope' } {'slexVariantSubsystems/sine1' } {'slexVariantSubsystems/sine2' } {'slexVariantSubsystems/sine3' } {'slexVariantSubsystems/Out1' }
Using the Simulink.match.codeCompileVariants
filter returns the blocks that are part of the generated C code.
slexVariantSubsystems([],[],[],"compileForCodegen"); slexVariantSubsystems([],[],[],"term"); find_system("slexVariantSubsystems",MatchFilter=@Simulink.match.codeCompileVariants)
ans = 25×1 cell {'slexVariantSubsystems' } {'slexVariantSubsystems/Controller' } {'slexVariantSubsystems/Controller/sensor1' } {'slexVariantSubsystems/Controller/sensor2' } {'slexVariantSubsystems/Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller' } {'slexVariantSubsystems/Controller/Linear Controller/sensor1' } {'slexVariantSubsystems/Controller/Linear Controller/sensor2' } {'slexVariantSubsystems/Controller/Linear Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller/Add' } {'slexVariantSubsystems/Controller/Linear Controller/Discrete↵Transfer Fcn'} {'slexVariantSubsystems/Controller/Linear Controller/Out1' } {'slexVariantSubsystems/Controller/Nonlinear Controller' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor1' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor2' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor3' } {'slexVariantSubsystems/Controller/Nonlinear Controller/1-D Lookup Table' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Add' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Out1' } {'slexVariantSubsystems/Controller/Out1' } {'slexVariantSubsystems/Scope' } {'slexVariantSubsystems/sine1' } {'slexVariantSubsystems/sine2' } {'slexVariantSubsystems/sine3' } {'slexVariantSubsystems/Out1' }
Find All Blocks Irrespective of Block Activeness
Use the Simulink.match.allVariants()
filter to find all blocks irrespective of whether the block is active or inactive due to variants.
find_system(model,MatchFilter=@Simulink.match.allVariants)
ans = 25×1 cell {'slexVariantSubsystems' } {'slexVariantSubsystems/Controller' } {'slexVariantSubsystems/Controller/sensor1' } {'slexVariantSubsystems/Controller/sensor2' } {'slexVariantSubsystems/Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller' } {'slexVariantSubsystems/Controller/Linear Controller/sensor1' } {'slexVariantSubsystems/Controller/Linear Controller/sensor2' } {'slexVariantSubsystems/Controller/Linear Controller/sensor3' } {'slexVariantSubsystems/Controller/Linear Controller/Add' } {'slexVariantSubsystems/Controller/Linear Controller/Discrete↵Transfer Fcn'} {'slexVariantSubsystems/Controller/Linear Controller/Out1' } {'slexVariantSubsystems/Controller/Nonlinear Controller' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor1' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor2' } {'slexVariantSubsystems/Controller/Nonlinear Controller/sensor3' } {'slexVariantSubsystems/Controller/Nonlinear Controller/1-D Lookup Table' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Add' } {'slexVariantSubsystems/Controller/Nonlinear Controller/Out1' } {'slexVariantSubsystems/Controller/Out1' } {'slexVariantSubsystems/Scope' } {'slexVariantSubsystems/sine1' } {'slexVariantSubsystems/sine2' } {'slexVariantSubsystems/sine3' } {'slexVariantSubsystems/Out1' }
Input Arguments
Model to search, specified as the full model path name, a cell array of model path names, a handle, or a vector of handles.
Example: 'MyModel/Subsystem1'
Example: {'vdp','ex_sldemo_clutch'}
Name-Value Arguments
Specify optional arguments as Name1 = Value1,...,NameN = ValueN
, whereName
is the argument name and Value
is the value you want to assign to the argument. Name-value arguments must appear after other arguments.
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: SearchDepth = '0',LookUnderMasks = 'none',BlockType = 'Goto'
searches in loaded models, excluding masked subsystems, for Goto blocks.
When you use the find_system
function, Name = Value
arguments can include:
- Search criteria, for example
CaseSensitive = 'on'
- Parameter values, for example
BlockType = 'Gain'
You can specify the search criteria in any order and the parameter values in any order, but the search criteria must precede the parameter values.
For information about block parameters, see Programmatically Specify Block Parameters and Properties.
Option to search block dialog box parameters for a value, specified as a character vector or string scalar. This argument must follow the other search criteria arguments.
Option to consider text case when matching, specified as'on'
or 'off'
.
Option to include lines, ports, and annotations within models in the search, specified as 'on'
or'off'
. When this option is set to'on'
, find_system
returns a vector of handles regardless of whether you specify theModel argument as the full model path name, a cell array of model path names, a handle, or a vector of handles.
Option to search for a specific type of model element, specified as one of these:
'block'
'line'
'port'
'annotation'
To find lines, ports, or annotations in the model, you must first specify the value of FindAll
as'on'
, and then the value ofType
. You can specify other search criteria options before, after, and between FindAll
andType
. For example, to find an annotation in a model named myModel
and look under masks, enter this command in the MATLAB® Command Window.
find_system('myModel', FindAll = 'on',... LookUnderMasks = 'all',Type = 'annotation')
Option to return only the first result and then stop the search, specified as 'on'
or 'off'
.
Option to look inside a referenced subsystem in a model and list child blocks, specified as 'on'
or'off'
.
Option to search under blocks in a model and list child blocks, specified as 'on'
or 'off'
. When you enable LookUnderModelBlocks
,find_system
loads the top-level and all the referenced models, and searches recursively in all models in the hierarchy.
Option to follow links into library blocks, specified as'on'
or 'off'
. If you do not specify a model to search, find_system
includes loaded libraries in the results, whether you set'FollowLinks'
to 'on'
or'off'
. You can use'FollowLinks'
with'LookUnderMasks'
to update library links in subsystems. See Update Library Links in a Subsystem.
Option to include commented blocks in the search, specified as'on'
or 'off'
.
Option to load any partially loaded models, specified as'on'
to load models or 'off'
to disable loading. Use this option, for example, to prevent load warnings.
Option for searching under masks, specified as one of these:
'none'
— Search skips masked subsystems.'all'
— Search includes all masked subsystems.'functional'
— Search includes masked subsystems that have icon drawing commands or mask initialization commands without having parameters, description, help strings, and UI elements.'graphical'
— Search includes masked subsystems that have only icon drawing commands without having workspaces, dialogs, help strings, and UI elements.
Note
The option 'none'
replaces the former option'off'
. The option 'all'
replaces the former option 'on'
.
Option to treat search expressions as regular expressions, specified as 'on'
or 'off'
. When'RegExp'
is set to 'on'
, the search treats search expressions as regular expressions. To learn more about MATLAB regular expressions, see Regular Expressions.
Option to restrict the search depth to the specified level, specified as a positive integer, character vector, or string scalar. 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, and so forth. The default is to search all levels.
Note
The Variants
argument will be removed. UseMatchFilter instead. For more information, see Version History.
Option for searching variants, specified as one of these:
'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 is part of the generated code.
This search constraint applies only to Variant Subsystem blocks that have the Variant control mode set to expression
orlabel
. Use the find_system
function with the MatchFilter
option to operate on all types of variant blocks.
Option to match and filter elements such as blocks, model, lines, ports, and annotations in a search, specified as a function handle. UseMatchFilter
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
element
is 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 whenelement
is a subsystem. The default value isfalse
. If this value is set totrue
, the entire subsystem is omitted from the search.
For an example that shows how to create a custom match filter function, see Filter find_system Search Using Custom MatchFilter Functions.
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.Simulink.match.variantAssemblySubsystems
— Filter function to find all the Variant Assembly Subsystem blocks.
For an example that shows the use of these filters, seeFind Variant Blocks Using find_system with Built-In MatchFilter Functions.
Note
When using the @Simulink.match.allVariants
match filter to identify active and inactive variant choices of a Variant Subsystem block with the update diagram
activation time, the function lists the inactive variant choices but executes theLoadFcn
callback only for the active variant choice. It does not execute theLoadFcn
callbacks for inactive variant choices, as they do not impact the model execution.
To get correct results, you must compile the model before usingSimulink.match.activeVariants
andSimulink.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, seeCompare Pre-Compile and Post-Compile Behavior of Match Filters for Variant Blocks.
Edit-time filter functions for Variant Subsystem blocks:
Simulink.match.legacy.filterOutCodeInactiveVariantSubsystemChoices
— Filter function to find Variant Subsystem choice blocks that are active in simulation or part of generated code. This function produces similar results as the'ActivePlusCodeVariants'
option of the Variants argument.Simulink.match.legacy.filterOutInactiveVariantSubsystemChoices
— Filter function to find active Variant Subsystem choice blocks. This function produces similar results as the'ActiveVariants'
option of the Variants argument.
Limitations of edit-time filters:
- The filters do not use the post-compile block activeness information in theCompiledVariantInfo block parameter.
- The filters apply only to Variant Subsystem blocks that have these block parameter settings:
- Variant control mode set to
expression
orlabel
- Propagate conditions outside of variant subsystem set to
off
- Variant control mode set to
- 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
orSimulink.match.activeVariants
filters after model compilation.
Option to search for a specific type of signal line segment, specified as one of these:
'trunk'
– Line segment connected to an output port or not connected to a source'branch'
– Line segment connected to the trunk
To find signal line segments of a specific type, you must first specify the value of FindAll
as'on'
, then specify the value ofType
as 'line'
, and then specify the value of SegmentType
. You can specify other search criteria options before, after, and between theFindAll
, Type
, andSegmentType
options. For example, to find signal line segments in a model named myModel
that are trunks and look under masks, enter this command in the MATLAB Command Window.
trunkSegments = find_system('myModel',FindAll = 'on',.. LookUnderMasks = 'all',type='line',SegmentType = 'trunk');
Output Arguments
Matching objects found, returned as a cell array of path names or a vector of handles.
The objects found are returned as a cell array of path names when both of these conditions are met.
- The search criteria option
FindAll
is set to its default value,'off'
. - You specified Model as a path name or cell array of path names, or you did not specify a model.
The objects found are returned as a vector of handles when at least one of these conditions is met.
- You set the value of
FindAll
to'on'
. - You specified
Model
as a handle or vector of handles.
Version History
Introduced before R2006a
You can use the LookUnderModelBlocks
option to enable search under blocks in a model. For example,find_system("mymodel",LookUnderModelBlocks=on,BlockType="Constant")
searches for Constant blocks under all blocks in the modelmymodel
and all of the referenced models.
As part of the removal of the Variants
argument in a future release, these warnings have been introduced:
- When you use the
find_system
function without theVariants
argument, the function generates a warning if it skips the inactive choice of a Variant Subsystem block during the search.
Consider a model with a Variant Subsystem block that has two variant choices,Linear Controller
andNonlinear Controller
. TheNonlinear Controller
block is the active choice.
This command skips the inactiveLinear Controller
block and generates a warning.
blocks = find_system('sldemo_variant_subsystems/Controller')
Warning: Using find_system without the 'Variants' argument skips inactive Variant
Subsystem blocks in the search. This behavior will change in a future release to
look at all choices of the Variant Subsystem. To find blocks thatare active in
simulation or code generation, compile the model and use the built-in variant
filters with the 'MatchFilter' option.
blocks =
12×1 cell array
{'sldemo_variant_subsystems/Controller' }
{'sldemo_variant_subsystems/Controller/sensor1' }
{'sldemo_variant_subsystems/Controller/sensor2' }
{'sldemo_variant_subsystems/Controller/sensor3' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/sensor1' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/sensor2' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/sensor3' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/1-D Lookup Table'}
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/Add' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/Out1' }
{'sldemo_variant_subsystems/Controller/Out1' } - When you use the
Variants
argument with its value set to'AllVariants'
, the function generates a warning.
blocks = find_system('sldemo_variant_subsystems/Controller',...
'Variants','AllVariants')
Warning: 'Variants' will be removed. Instead of using 'Variants' with value set to
'AllVariants', use 'MatchFilter' with value set to @Simulink.match.allVariants.
blocks =
19×1 cell array
{'sldemo_variant_subsystems/Controller' }
{'sldemo_variant_subsystems/Controller/sensor1' }
{'sldemo_variant_subsystems/Controller/sensor2' }
{'sldemo_variant_subsystems/Controller/sensor3' }
{'sldemo_variant_subsystems/Controller/Linear Controller' }
{'sldemo_variant_subsystems/Controller/Linear Controller/sensor1' }
{'sldemo_variant_subsystems/Controller/Linear Controller/sensor2' }
{'sldemo_variant_subsystems/Controller/Linear Controller/sensor3' }
{'sldemo_variant_subsystems/Controller/Linear Controller/Add' }
{'sldemo_variant_subsystems/Controller/Linear Controller/Discrete↵Transfer Fcn'}
{'sldemo_variant_subsystems/Controller/Linear Controller/Out1' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/sensor1' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/sensor2' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/sensor3' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/1-D Lookup Table' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/Add' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/Out1' }
{'sldemo_variant_subsystems/Controller/Out1' }
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 |
---|---|
find_system(model,'Variants', ... 'AllVariants'); | find_system(model,'MatchFilter', ... @Simulink.match.allVariants); |
Variants
: When you use thefind_system
function without specifying theVariants
argument, the function currently includes only the active variant choice for Variant Subsystem blocks in the search by default.
For other variant blocks such as Variant Source,Variant Sink, or Variant Subsystem blocks with the Propagate conditions outside of variant subsystem parameter set toon
, the function includes all choices in the search.
Consider a model with a Variant Subsystem that has two variant choices,Linear Controller
andNonlinear Controller
.
This command returns only the active Add blocks in the model.
add_blocks = find_system('sldemo_variant_subsystems/Controller',...
'BlockType','Sum')
add_blocks =
1×1 cell array
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/Add'}MatchFilter
: When you use thefind_system
function with theMatchFilter
argument, the function applies the filters on the active and inactive variant choices by default.
Consider a model with a Variant Subsystem that has two variant choices,Linear Controller
andNonlinear Controller
. The filter functionfindAddBlocks
finds all the Add blocks in the model.
function match = findAddBlocks(handle)
match = strcmp(get_param(handle, 'Type'), 'block') &&...
strcmp(get_param(handle, 'BlockType'), 'Sum');
end
This command returns the active and inactive Add blocks in the model.
add_blocks = find_system('sldemo_variant_subsystems','MatchFilter',...
@findAddBlocks)
add_blocks =
2×1 cell array
{'sldemo_variant_subsystems/Controller/Linear Controller/Add' }
{'sldemo_variant_subsystems/Controller/Nonlinear Controller/Add'}
The Variants
argument will be removed fromfind_system
in a future release. Function calls that use the Variants
argument continue to work with a warning.
Using the find_system
function with theVariants
argument produces inconsistent search results. The find_system
function is an edit-time operation, 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 thefind_system
function with theMatchFilter
argument.
This table lists the recommended replacement for different values of theVariants
argument.
To Be Removed | Recommended Replacement |
---|---|
find_system(model,'Variants', ... 'ActiveVariants'); | set_param(model,'SimulationCommand','update'); find_system(model,'MatchFilter', ... @Simulink.match.activeVariants); |
find_system(model,'Variants', ... 'ActivePlusCodeVariants'); | model([], [], [], 'compileForCodegen'); activeBlks= find_system(model,'MatchFilter', ... @Simulink.match.codeCompileVariants); model([], [], [], 'term'); |
When you use the find_system
function, you cannot specify both of the MatchFilter
and Variants
arguments.
This command produces an error.
find_system(bdroot,'MatchFilter',@Simulink.match.activeVariants,... 'Variants','ActiveVariants');
To match and filter model elements during a search, you can define a custom filter function and pass the function handle as value to theMatchFilter
name-value argument.
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
, andSimulink.match.allVariants
, after compiling the model.