Find systems, blocks, lines, ports, and annotations
returns loaded systems and the objects in those systems 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 system that meet the specified criteria.Objects
= find_system(System
,Name,Value
)
Return the names of all loaded systems and their blocks.
load_system('vdp')
find_system
ans = 15x1 cell
{'vdp' }
{'vdp/Constant' }
{'vdp/More Info' }
{'vdp/More Info/Model Info'}
{'vdp/Mu' }
{'vdp/Mux' }
{'vdp/Product' }
{'vdp/Scope' }
{'vdp/Square' }
{'vdp/Sum' }
{'vdp/Sum1' }
{'vdp/x1' }
{'vdp/x2' }
{'vdp/Out1' }
{'vdp/Out2' }
Returns loaded systems and libraries, including vdp
.
Return vdp
system and its blocks.
load_system({'vdp','fuelsys'}) find_system('vdp')
ans = 15x1 cell
{'vdp' }
{'vdp/Constant' }
{'vdp/More Info' }
{'vdp/More Info/Model Info'}
{'vdp/Mu' }
{'vdp/Mux' }
{'vdp/Product' }
{'vdp/Scope' }
{'vdp/Square' }
{'vdp/Sum' }
{'vdp/Sum1' }
{'vdp/x1' }
{'vdp/x2' }
{'vdp/Out1' }
{'vdp/Out2' }
Return the names of the loaded models, subsystems, and libraries. A subsystem name is returned only if the subsystem can be loaded independently.
load_system('vdp'); find_system('type','block_diagram')
ans = 1x1 cell array
{'vdp'}
Return the names of all Goto blocks that are children of the Unlocked subsystem in the sldemo_clutch
system.
load_system('sldemo_clutch'); find_system('sldemo_clutch/Unlocked','SearchDepth',1,'BlockType','Goto')
ans = 2x1 cell
{'sldemo_clutch/Unlocked/Goto' }
{'sldemo_clutch/Unlocked/Goto1'}
Search in the vdp
system and return the names of all Gain blocks whose Gain value is set to 1
.
load_system('vdp'); find_system('vdp','BlockType','Gain','Gain','1')
ans = 1x1 cell array
{'vdp/Mu'}
Get the handles of all lines and annotations in the vdp
system. With 'FindAll'
, the function returns handles regardless of how you specify the system to search.
load_system('vdp'); L = find_system('vdp','FindAll','on','type','line')
L = 19×1
34.0052
33.0052
32.0052
31.0052
30.0052
29.0052
28.0052
27.0052
26.0052
25.0052
⋮
A = find_system('vdp','FindAll','on','type','annotation')
A = 2×1
36.0052
35.0052
Find any block dialog box parameters with a value of
0
in the vdp
and
fuelsys
systems.
load_system({'vdp','fuelsys'}) find_system({'vdp','fuelsys'},'BlockDialogParams','0')
ans = 'vdp/x2' 'vdp/Out1' 'vdp/Out2' 'fuelsys/Constant2' 'fuelsys/Constant4' 'fuelsys/Constant5' 'fuelsys/engine …' 'fuelsys/engine …' 'fuelsys/engine …' 'fuelsys/engine …' . . .
Find all blocks in the top level of the currently loaded systems with a block dialog parameter value that starts with 3
.
load_system({'fuelsys','vdp'}); find_system('SearchDepth','1','regexp','on','BlockDialogParams','^3')
ans = 4x1 cell
{'vdp/Scope' }
{'vdp/Scope' }
{'vdp/Square' }
{'fuelsys/Nominal...'}
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 inport and outport blocks in the sldemo_clutch
model.
load_system('sldemo_clutch'); find_system('sldemo_clutch','regexp','on','blocktype','port')
ans = 39x1 cell
{'sldemo_clutch/Friction...' }
{'sldemo_clutch/Friction...' }
{'sldemo_clutch/Friction...' }
{'sldemo_clutch/Friction Mode Logic/Tin' }
{'sldemo_clutch/Friction Mode Logic/Tfmaxs' }
{'sldemo_clutch/Friction Mode Logic/Break Apart...' }
{'sldemo_clutch/Friction Mode Logic/Break Apart...' }
{'sldemo_clutch/Friction Mode Logic/Break Apart...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup...' }
{'sldemo_clutch/Friction Mode Logic/Lockup FSM/lock' }
{'sldemo_clutch/Friction Mode Logic/Lockup FSM/unlock' }
{'sldemo_clutch/Friction Mode Logic/Lockup FSM/locked' }
{'sldemo_clutch/Friction Mode Logic/Requisite Friction/Tin'}
{'sldemo_clutch/Friction Mode Logic/Requisite Friction/Tf' }
{'sldemo_clutch/Friction Mode Logic/locked' }
{'sldemo_clutch/Friction Mode Logic/lock' }
{'sldemo_clutch/Friction Mode Logic/unlock' }
{'sldemo_clutch/Friction Mode Logic/Tf' }
{'sldemo_clutch/Locked/Tin' }
{'sldemo_clutch/Locked/w' }
{'sldemo_clutch/Unlocked/Tfmaxk' }
{'sldemo_clutch/Unlocked/Tin' }
{'sldemo_clutch/Unlocked/we' }
⋮
In this example, myModel
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','on','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','on','FollowLinks','on')
Updating Link: myModel/Subsystem/Gain Updating Link: myModel/Subsystem/Gain ans = 'myModel' 'myModel/Subsystem' 'myModel/Subsystem/Gain'
Provide the system to find_system
as a handle. Search for block dialog box parameters with a value of 0
. If you make multiple calls to get_param
for the same block, then using the block handle is more efficient than specifying the full block path as a character vector.
load_system('vdp'); sys = get_param('vdp','Handle'); find_system(sys,'BlockDialogParams','0')
ans = 8×1
3.0055
4.0055
8.0055
13.0055
14.0055
14.0055
15.0055
15.0055
System
— System to searchSystem to search, specified as the full system path name, a cell array of system path names, a handle, or a vector of handles.
Example: 'MyModel/Subsystem1'
Example: {'vdp','fuelsys'}
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'SearchDepth','0','LookUnderMasks','none','BlockType','Goto'
searches in loaded systems, excluding masked subsystems, for Goto
blocks.When you use the find_system
function,
Name,Value
pair arguments can include search constraints and
parameter name and value pairs. You can specify search constraints in any order, but
they must precede the parameter name and value pairs.
See Block-Specific Parameters for the list of block parameters.
'BlockDialogParams'
— Option to search block dialog box parameters for the specified valueOption to search block dialog box parameters for the specified value,
specified as the comma-separated pair consisting of
'BlockDialogParams'
and a character vector or
string scalar. This pair must follow the other search constraint
pairs.
'CaseSensitive'
— Option to consider case when matching'on'
(default) | 'off'
Option to consider case when matching, specified as the
comma-separated pair consisting of 'CaseSensitive'
and 'on'
for case-sensitive searching or
'off'
.
'FindAll'
— Option to include lines, ports, and annotations within systems'off'
(default) | 'on'
Option to include lines, ports, and annotations in systems in the
search, specified as the comma-separated pair consisting of
'FindAll'
and 'on'
or
'off'
.When this option is set to
'on'
, find_system
returns a
vector of handles regardless of how you specify the
System
argument .
'FirstResultOnly'
— Option to return only the first result'off'
(default) | 'on'
Option to return only the first result and then stop the search,
specified as the comma-separated pair consisting of
'FirstResultOnly'
and 'on'
or
'off'
.
'LookInsideSubsystemReference'
— Option to look inside a referenced subsystem'on'
(default) | 'off'
Option to look inside a referenced subsystem in a model and list child
blocks specified as the comma-separated pair consisting of
'LookInsideSubsystemReference'
and
'on'
or 'off'
.
'FollowLinks'
— Option to follow links into library blocks'off'
(default) | 'on'
Option to follow links into library blocks, specified as the
comma-separated pair consisting of 'FollowLinks'
and
'on'
or 'off'
. If you do not
specify a system 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.
'IncludeCommented'
— Option to include commented blocks'off'
(default) | 'on'
Option to include commented blocks in the search, specified as the
comma-separated pair consisting of 'IncludeCommented'
and 'on'
or 'off'
.
'LoadFullyIfNeeded'
— Option to load any partially loaded models'on'
(default) | 'off'
Option to load any partially loaded models, specified as the
comma-separated pair of 'LoadFullyIfNeeded'
and
'on'
to load models or 'off'
to disable loading. Use this option, for example, to prevent load
warnings.
'LookUnderMasks'
— Options for searching under masks'graphical'
(default) | 'none'
| 'functional'
| 'all'
| 'on'
| 'off'
Options for searching under masks, specified as the comma-separated
pair consisting of 'LookUnderMasks'
and one of these options:
'graphical'
— Search includes masked
subsystems that have no workspaces and no dialogs.
'none'
— Search skips masked
subsystems.
'functional'
— Search includes masked
subsystems that do not have dialogs.
'all'
— Search includes all masked
subsystems.
'on'
— Search includes all masked
subsystems.
'off'
— Search skips masked
subsystem.
'RegExp'
— Option to treat search expressions as regular expressions'off'
(default) | 'on'
Option to treat search expressions as regular expressions specified as
the comma-separated pair consisting of 'RegExp'
and
'on'
to treat search expressions as regular
expressions or 'off'
. To learn more about MATLAB® regular expressions, see Regular Expressions.
'SearchDepth'
— Option to restrict the search depthOption to restrict the search depth to the specified level, specified
as the comma-separated pair consisting of
'SearchDepth'
and a positive integer character
vector or string scalar. For example, specify '0'
to
search loaded systems only, '1'
for blocks and
subsystems of the top-level system, '2'
for the
top-level system and its children, etc. The default is to search all
levels.
'Variants'
— Options for searching variants'ActiveVariants'
(default) | 'AllVariants'
| 'ActivePlusCodeVariants'
Options for searching variants, specified as the comma-separated pair
consisting of 'Variants'
and one of these options:
'ActiveVariants'
— Search in only the
active variant subsystems.
'AllVariants'
— Search in all
variants.
'ActivePlusCodeVariants'
— Search all
variants if any generate preprocessor conditionals.
Otherwise, search only the active variant.
Note
This search constraint applies only to variant subsystems. To work on all other variant blocks, use Variants MatchFilter option.
'MatchFilter'
— Function handle to match elementsA Function handle to match elements in a search, such as blocks,
system, lines, ports, and annotations. Use
MatchFilter
to determine whether the elements
should be selected or skipped in a search.
Example: Use MatchFilter
to find all non
Inport and Outport blocks in a model
using your own defined filter function,
nonInOutBlocks
:
blks = find_system('ModelName', 'MatchFilter', @nonInOutBlocks)
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
This example shows how to use MatchFilter
with
second output argument prune
.
[match, prune] = fcn(element) where element - Handle of the block being processed. match - Logical. If false, skip the element. prune - Optional logical (default false). If true, do not look in subsystems.
Variants: Simulink provides
Simulink.match.activeVariants
and
Simulink.match.codeCompileVariants
match filter
functions for variant blocks, which you can use to find active variants
or code compile variant blocks. To do so, compile the model and apply
the appropriate MatchFilter
options:
Simulink.match.activeVariants
- Matches
blocks that are active in simulation after model
compilation
Simulink.match.codeCompileVariants
-
Matches blocks that are part of generated code after model
compilation
Example: Use Simulink.match.activeVariants
option to find active variants in a model:
set_param(model, 'SimulationCommand', 'update'); activeBlks = find_system(model, 'MatchFilter', @Simulink.match.activeVariants);
Example: Use Simulink.match.codeCompileVariants
option to find variant choices that are part of the generated C
code:
MODEL([],[],[],'compileForRTW') find_system(MODEL, 'MatchFilter', @Simulink.match.codeCompileVariants); MODEL([],[],[],'term')
Objects
— Matching objectsMatching objects found, returned as:
A cell array of path names if you specified
System
as a path name or cell array of
path names, or if you did not specify a system
A vector of handles if you specified
System
as a handle or vector of
handles
find_mdlrefs
| get_param
| getSimulinkBlockHandle
| Model
Explorer | set_param
| Simulink
Editor | Simulink.allBlockDiagrams
| Simulink.findBlocks
| Simulink.findBlocksOfType
You have a modified version of this example. Do you want to open this example with your edits?