find_system
R2026bFind models, blocks, lines, ports, and annotations
Syntax
Description
returns loaded
models and their blocks, including subsystems.Objects = find_system
returns loaded models and the objects in those models that meet the criteria
specified by one or more Objects = find_system(Name=Value)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.
returns the objects in the specified model that meet the specified criteria.Objects = find_system(Model,Name=Value)
Examples
Suppose you have a loaded model named
myModel.
Get the model name and the paths of all blocks the model contains.
p = find_system("myModel",Type="block")
Suppose you have a loaded model named
myModel. Get the handles of all the blocks the model
contains.
Get the model handle.
hModel = get_param("myModel","Handle");
Get the handles of all blocks the model contains.
hBlocks = find_system(hModel,Type="block")Suppose you have a loaded model named
myModel that contains a Subsystem block
named mySubsystem. Get the handles of all Transfer
Fcn blocks the subsystem contains.
Get the handle of the Subsystem block.
hModel = get_param("myModel/mySubsystem","Handle");
Get the handles of all Transfer Fcn blocks the subsystem contains.
hBlocks = find_system(hModel,BlockType="TransferFcn")Suppose you have a loaded model named
myModel. Get the handles of all Integrator
blocks in the model whose initial condition is zero.
Get the handle of the model.
hModel = get_param("myModel","Handle");
Get the handles of all Integrator blocks for which the
value of the InitialCondition parameter is
0.
hBlocks = find_system(hModel,BlockType="Integrator",InitialCondition="0")
Suppose you have a loaded model named
myModel. Get the handles of all Subsystem
blocks in the model whose name contains the keyword
speed
Get the handle of the model.
hModel = get_param("myModel","Handle");
Get the handles of all Subsystem blocks whose name contains
the keyword speed.
hBlocks = find_system(hModel,Regexp="on",CaseSensitive="off",BlockType="Subsystem",Name='.*speed.*')
Suppose you have a loaded model named
myModel that contains a Subsystem block
named mySubsystem. Get the handles of all signal lines the
subsystem contains.
Get the handle of the Subsystem block.
hModel = get_param("myModel/mySubsystem","Handle");
Get the handles of all signal lines the subsystem contains. Remember to
set FindAll to "on" in order to
include signal lines, ports, and annotations in the search. Then, narrow
down the search to only signal lines by setting Type to
"line".
hLines = find_system(h,FindAll="on",Type="line")
To check your work, open the subsystem.
open_system(h);
Highlight the signal lines whose handles are stored in
hLines.
hilite_system(hLines)
Get the names of all loaded models, libraries, and subsystems saved to their own files.
find_system(Type="block_diagram")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 the find_system function with
SearchInsideLibraryLinks 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,SearchUnderMasks="all",'SearchInsideLibraryLinks="off")
ans =
'myModel'
'myModel/Subsystem'
Use the find_system function with
SearchInsideLibraryLinks set to
"on". The find_system function
updates the library links and returns the block in the subsystem.
find_system(bdroot,SearchUnderMasks="all",SearchInsideLibraryLinks="on")
Updating Link: myModel/Subsystem/Gain
Updating Link: myModel/Subsystem/Gain
ans =
'myModel'
'myModel/Subsystem'
'myModel/Subsystem/Gain'
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 exclude Inport and Outport blocks in a model from the search, define a custom filter function as shown in the file nonInOutBlocks.m. The function checks the type of each block and returns true only for blocks that are not Inport or Outport.
type nonInOutBlocks.mfunction 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
To apply this filter to the slexVariantSubsystemEnableChoice model, provide the function handle as the value for the MatchFilter argument in the find_system command.
load_system("slexVariantSubsystemEnableChoice"); blks = find_system("slexVariantSubsystemEnableChoice","MatchFilter",@nonInOutBlocks)
blks = 12×1 cell
{'slexVariantSubsystemEnableChoice' }
{'slexVariantSubsystemEnableChoice/Controller' }
{'slexVariantSubsystemEnableChoice/Controller/Enable' }
{'slexVariantSubsystemEnableChoice/Controller/Linear' }
{'slexVariantSubsystemEnableChoice/Controller/Linear/Enable' }
{'slexVariantSubsystemEnableChoice/Controller/Linear/Discrete Filter' }
{'slexVariantSubsystemEnableChoice/Controller/Nonlinear' }
{'slexVariantSubsystemEnableChoice/Controller/Nonlinear/Enable' }
{'slexVariantSubsystemEnableChoice/Controller/Nonlinear/Discrete Filter'}
{'slexVariantSubsystemEnableChoice/Controller/Nonlinear/Lookup Table' }
{'slexVariantSubsystemEnableChoice/Sine Wave' }
{'slexVariantSubsystemEnableChoice/help' }
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 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 blocks 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 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.
find_system(model, ... 'MatchFilter',@Simulink.match.legacy.filterOutCodeInactiveVariantSubsystemChoices);
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.
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.activeVariantsSimulink.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
Models and subsystems to search. Specify models as handles or names. Specify subsystems as the block paths of the corresponding Subsystem blocks. Format handles as numeric scalars or numeric arrays. Format names as strings, string arrays, character vectors, or cell arrays of character vectors.
For information about getting handles and paths, see Get Handles and Paths.
Example: "myModel/mySubsystem"
Example: ["myModel1","myModel2"]
Data Types: double | array of doubles | string | string array | character vector | cell array of character vectors
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: SearchDepth="0",SearchUnderMasks="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.
Search Criteria
Option to search block dialog box parameters for a value, specified as a string or character vector. This argument must follow the other search criteria arguments.
Data Types: string | character vector
Option to consider text case, specified as "on" or
"off".
Data Types: string | character vector
Option to include lines, ports, and annotations in the search,
specified as "on" or 'off'. When
this option is set to "off", the
find_system function returns a vector of
handles regardless of whether you specify the Model
argument as the full model path name, a cell array of model path names,
a handle, or a vector of handles.
Data Types: string | character vector
Option to search for a specific type of model element, specified as one of these:
"block""line""port""annotation""block_diagram"
To find lines, ports, or annotations, you must first specify the value
of FindAll as "on", and then you
can optionally narrow down the type of model element you want to search
for by specifying the value of Type. You can specify
other search criteria options before, after, and between
FindAll and Type. 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",SearchUnderMasks="all",Type="annotation")
Data Types: string | character vector
Option to return only the first result and then stop the search,
specified as "on" or "off".
Data Types: string | character vector
Option to search inside a referenced subsystem in a model and list
child blocks, specified as "on" or
"off".
Data Types: string | character vector
Option to search inside referenced models in a model and list child
blocks, specified as "on" or
"off". When you enable
SearchInsideModelReferences, the
find_system function loads the top-level and
all the referenced models, and searches recursively in all models in the
hierarchy.
Data Types: string | character vector
Option to search inside library links, specified as
"on" or "off". If you do not
specify a model to search, the find_system function
includes loaded libraries in the results regardless of whether you set
SearchInsideLibraryLinks to
"on" or "off". You can use
SearchInsideLibraryLinks with
SearchUnderMasks to update library links in
subsystems. See Update Library Links in a Subsystem.
Data Types: string | character vector
Option to include commented blocks in the search, specified as
"on" or "off".
Data Types: string | character vector
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.
Data Types: string | character vector
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".
Data Types: string | character vector
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.
Data Types: string | character vector
Option to restrict the search depth to the specified level, specified
as a positive integer, 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, and so forth. The default is to search all
levels.
Data Types: string | character vector
Note
The Variants argument will be removed. Use
MatchFilter 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 or
label. Use the find_system
function with the MatchFilter option to operate on
all types of variant blocks.
Data Types: string | character vector
Option to match and filter model elements such as blocks, model,
signal lines, ports, and annotations in a search, specified as a
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, signal 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 model element as input and returns two outputs.
function [match, prune] = func(element)
The input
elementis the handle of the model element 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 when the model element 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— Find blocks that are active in simulation after model compilation.Simulink.match.codeCompileVariants— Find blocks that are part of generated code after model compilation.Simulink.match.allVariants— Find all blocks irrespective of whether the block is active or inactive due to variants.Simulink.match.variantAssemblySubsystems— Find all the Variant Assembly Subsystem blocks.
For an example that shows the use of these filters, see Find Variant Blocks Using find_system with Built-In MatchFilter Functions.
Note
When using the @Simulink.match.allVariants
match filter to identify blocks inside all the choices of a
Variant
Subsystem block with the update
diagram activation time, the function lists
the inactive variant choices but executes the
LoadFcn callback only for the active
variant choice. The function does not execute the
LoadFcn callbacks for inactive variant
choices, as they do not impact the model execution.
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 theActivePlusCodeVariantsoption 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 theActiveVariantsoption 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 the
find_systemfunction, thefind_mdlrefsfunction, andSimulink.FindOptionsobjects.
To operate on all types of variant blocks, use the
Simulink.match.codeCompileVariants or
Simulink.match.activeVariants filters after model
compilation.
Option to search for specific parts of a branched signal line, specified as one of these:
"trunk"– Branch connected to an output port or not connected to a source"branch"– Branch connected to the trunk
To find specific parts of branched signal lines, you must first
specify the value of FindAll as
"on", then specify the value of
Type as "line", and then
specify the value of SegmentType. You can specify
other search criteria options before, after, and between the
FindAll, Type, and
SegmentType 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",.. SearchUnderMasks="all",type="line",SegmentType="trunk");
Data Types: string | character vector
Output Arguments
Matching objects found, returned as handles, names, or paths. Handles are formatted as numeric scalars or numeric arrays. Names and paths are formatted as character vectors or cell arrays of character vectors.
The objects found are returned as names or paths when both of these conditions are met.
The search criteria option
FindAllis set to its default value,"off".You specified
Modelusing names, or you did not specify a model.
The objects found are returned as handles when at least one of these conditions is met.
You set the value of
FindAllto"on".You specified
Modelusing handles.
Data Types: double | array of doubles | character vector | cell array of character vectors
Version History
Introduced before R2006aYou 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 model
mymodel and all of the referenced models.
Several options 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.
As part of the removal of the Variants argument in a future
release, these warnings have been introduced:
When you use the
find_systemfunction without theVariantsargument, 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 ControllerandNonlinear Controller. TheNonlinear Controllerblock is the active choice.This command skips the inactive
Linear Controllerblock 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
Variantsargument 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_systemfunction without specifying theVariantsargument, 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 to
on, the function includes all choices in the search.Consider a model with a Variant Subsystem that has two variant choices,
Linear ControllerandNonlinear 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_systemfunction with theMatchFilterargument, 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 ControllerandNonlinear Controller. The filter functionfindAddBlocksfinds 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 from
find_system in a future release. Function calls that use
the Variants argument continue to work with a warning.
Using the find_system function with the
Variants 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 the
find_system function with the
MatchFilter argument.
This table lists the recommended replacement for different values of the
Variants 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 the
MatchFilter 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, 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.
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)