Find referenced models and Model blocks in model hierarchy
[
provides additional search options using one or more name-value pairs. For example,
to keep the models loaded instead of temporarily loading them, set
models
,blocks
]
= find_mdlrefs(system
,Name,Value
)KeepModelsLoaded
to true
.
Find referenced models and Model blocks for all models referenced by the specified model.
load_system('sldemo_mdlref_basic'); [myModels,myModelBlks] = find_mdlrefs('sldemo_mdlref_basic')
myModels = 2x1 cell
{'sldemo_mdlref_counter'}
{'sldemo_mdlref_basic' }
myModelBlks = 3x1 cell
{'sldemo_mdlref_basic/CounterA'}
{'sldemo_mdlref_basic/CounterB'}
{'sldemo_mdlref_basic/CounterC'}
By default, the find_mdlrefs
function loads and then closes the models that were not already loaded. To identify what models are loaded, use the find_system
function.
find_mdlrefs('sldemo_mdlref_depgraph'); find_system('type','block_diagram')
ans = 0x1 empty cell array
To find and load all models in the model hierarchy, set KeepModelsLoaded
to true
.
find_mdlrefs('sldemo_mdlref_depgraph','KeepModelsLoaded',true); find_system('type','block_diagram')
ans = 7x1 cell
{'sldemo_mdlref_thermostat' }
{'sldemo_mdlref_heater' }
{'sldemo_mdlref_F2C' }
{'sldemo_mdlref_outdoor_temp'}
{'sldemo_mdlref_house' }
{'sldemo_mdlref_heat2cost' }
{'sldemo_mdlref_depgraph' }
The top model and all referenced models remain loaded. If you open sldemo_mdlref_depgraph
, you can navigate the model hierarchy without waiting for the referenced models to load as you open them.
system
— System name, block path, or handleSystem name, block path, or handle, specified as a character vector, string scalar, or numeric scalar.
The system must be an SLX file, MDL file, Model block, or Subsystem block.
If you specify a file name, do not include the file extension.
Data Types: double
| char
| string
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
.
refModels =
find_mdlrefs(topmodel,'KeepModelsLoaded',true,'ReturnTopModelAsLastElement',false)
'AllLevels'
— Levels to searchtrue
or
1
(default) | false
or 0
Levels to search, specified as the comma-separated pair consisting of
'AllLevels'
and a numeric or logical
1
(true
) or
0
(false
).
true
— Search all
Model blocks in the model hierarchy of the
specified system
.
false
— Search only the top-level
system.
Data Types: logical
'KeepModelsLoaded'
— Option to keep models loadedfalse
or
0
(default) | true
or 1
Option to keep models loaded, specified as the comma-separated pair
consisting of 'KeepModelsLoaded'
and a numeric or
logical 1
(true
) or
0
(false
).
By default the function loads and then closes the models that were not
already loaded. To keep the models loaded, set this argument to
true
. Keeping the models loaded can be useful if
you plan on interacting with the models after finding them.
Data Types: logical
'IncludeProtectedModels'
— Option to include protected modelsfalse
or
0
(default) | true
or 1
Option to include protected models in the search results, specified as
the comma-separated pair consisting of
'IncludeProtectedModels'
and a numeric or logical
1
(true
) or
0
(false
).
This setting only affects the returned list of referenced models; It does not affect the returned list of Model blocks.
Data Types: logical
'Variants'
— Option to include variant models'ActivePlusCodeVariants'
(default) | 'ActiveVariants'
| 'AllVariants'
Option to include variant models in the search results, specified as
the comma-separated pair consisting of 'Variants'
and
'ActivePlusCodeVariants'
,
'ActiveVariants'
, or
'AllVariants'
.
'ActivePlusCodeVariants'
— Include
all variant models in Variant Subsystem blocks
for which you set the Variant activation
time parameter to code
compile
.
'ActiveVariants'
— Include active
variant models for Variant Subsystem
blocks.
'AllVariants'
— Include all variant
models in Variant Subsystem blocks.
Note
This search constraint applies only to variant subsystems. To work on all other variant blocks, use Variants MatchFilter option.
Data Types: char
| string
'CaseSensitive'
— Option to match case when searchingtrue
(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 linksfalse
(default) | true
Option for the 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 blockstrue
(default) | false
Option for the 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'
Options to search variant subsystems, specified as:
'AllVariants'
— Search all variant
choices.
'ActiveVariants'
— Search only active
variant choices.
'ActivePlusCodeVariants'
— Search all
variant choices with 'Generate preprocessor
conditionals'
active. Otherwise, search only the
active variant choices.
Note
This search constraint applies only to variant subsystems. To work on all other variant blocks, use Variants MatchFilter option.
Data Types: char
| string
'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 model blocks
in a model by defining the filter function,
initFcnMdlBlocks
:
blks = find_mdlrefs('ModelName', 'MatchFilter', @initFcnMdlBlocks) function match = initFcnMdlBlocks(handle) match = ~isempty(get_param(hdl, 'InitFcn')); end
Example: 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, 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'); codecompileBlks = find_mdlrefs(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_mdlrefs(MODEL, 'MatchFilter', @Simulink.match.codeCompileVariants); MODEL([],[],[],'term')
'IncludeCommented'
— Option to include commented blocksfalse
or
0
(default) | true
or 1
Option to include commented blocks in the search results, specified as
the comma-separated pair consisting of
'IncludeCommented'
and a numeric or logical
1
(true
) or
0
(false
).
Data Types: logical
'ReturnTopModelAsLastElement'
— Option to include specified systemtrue
or
1
(default) | false
or 0
Option to include the specified system in the search results, ,
specified as the comma-separated pair consisting of
'ReturnTopModelAsLastElement'
and a numeric or
logical 1
(true
) or
0
(false
).
By default, the last element in the returned list of referenced models
is the name of the model, library, or subsystem file that you specified
with the system
argument. If you specify a block,
the last element is the name of the file that contains it.
Data Types: logical
models
— Names of modelsNames of models, returned as a cell array of character vectors.
By default, the last element is the name of the model, library, or
subsystem file that you specified with the system
argument. If you specify a block, the last element is the model, library, or
subsystem file that contains it.
blocks
— Names of Model blocksNames of Model blocks, returned as a cell array of character vectors.
find_mdlrefs
is discouragedNot recommended starting in R2020b
The find_mdlrefs
function provides two ways to specify
whether to search all levels of the model hierarchy. Both techniques give the same
results, but only the name-value pair technique allows you to specify additional
options.
Instead of specifying whether to search all levels of the model hierarchy with a
logical as the second argument, use the AllLevels
name-value
pair.
You have a modified version of this example. Do you want to open this example with your edits?