Given a model reference hierarchy, use the pathsToReferencedModel function to get the models and corresponding Model blocks between a top model and a referenced model.
Open the example project.
A project startup task opens the sldemo_mdlref_depgraph model, which is the top model in a model hierarchy.
Get the models and corresponding blocks between the sldemo_mdlref_depgraph top model and the sldemo_mdlref_F2C referenced model.
models = 4×1 cell
{'sldemo_mdlref_depgraph' }
{'sldemo_mdlref_outdoor_temp'}
{'sldemo_mdlref_heater' }
{'sldemo_mdlref_F2C' }
blocks =
1×2 BlockPath array with properties:
SubPath
isLoadingModel
isSavingModel
The returned models array includes four models, including the specified top and bottom models.
The returned blocks array includes one Simulink.BlockPath object for each instance of the referenced model. Based on dimensions of the array, the model hierarchy references the sldemo_mdlref_F2C model twice.
Inspect the first Simulink.BlockPath object.
ans =
Simulink.BlockPath
Package: Simulink
Block Path:
sldemo_mdlref_depgraph/outdoor temp
sldemo_mdlref_outdoor_temp/Fahrenheit to Celsius
Use the getBlock method to access block path strings from this object.
Methods
Each Model block in the block path is given relative to its parent model.
The sldemo_mdlref_depgraph model contains a Model block named outdoor temp.
The referenced sldemo_mdlref_outdoor_temp model contains a Model block named Fahrenheit to Celsius. As the last Model block in the path, this Model block references the sldemo_mdlref_F2C model.
Inspect the second Simulink.BlockPath object.
ans =
Simulink.BlockPath
Package: Simulink
Block Path:
sldemo_mdlref_depgraph/thermostat
sldemo_mdlref_heater/Fahrenheit to Celsius
Use the getBlock method to access block path strings from this object.
Methods
Each Model block in the block path is given relative to its parent model.
The sldemo_mdlref_depgraph model contains a Model block named thermostat.
The referenced sldemo_mdlref_heater model contains a Model block named Fahrenheit to Celsius. As the last Model block in the path, this Model block references the sldemo_mdlref_F2C model.