This example shows how to view dependencies among referenced models.
In this example, Simulink® generates files in the current working directory. If you do not want to generate files in this directory, you should change the working directory to a suitable directory before starting this example.
Open the example model. The model sldemo_mdlref_depgraph
looks like this:
Use the find_mdlrefs
utility function to find all Model blocks and all models that a model references. Type help find_mdlrefs
for more information about this function.
[refMdls, modelBlks] = find_mdlrefs('sldemo_mdlref_depgraph');
find_mdlrefs
returns two cell arrays, refMdls
and modelBlks
. refMdls
contains the names of all models that are directly or indirectly referenced by sldemo_mdlref_depgraph
. The last element in refMdls
is always the name of the input model. modelBlks
contains block paths for all Model blocks in the top model and all referenced models.
To view the dependency graph for the example model, double click on the blue box in the example model. Perform one of these actions to open the dependency viewer for a model: * Use the depview
function. * In the Modeling tab, select Compare > Dependencies > Models Only.
The next figure shows the dependency graph of sldemo_mdlref_depgraph
:
In the dependency graph, the gray nodes represent Simulink models. The directed lines indicate dependencies. For example, in the example model the link from sldemo_mdlref_depgraph
to sldemo_mdlref_house
indicates that sldemo_mdlref_depgraph
references sldemo_mdlref_house
. If the model had library links, you could select User-defined Libraries from the toolstrip to have the dependency viewer show libraries linked to by models in the hierarchy. When User-defined Libraries is selected, purple nodes are used to depict libraries.
To select a node, left-click on it.
To open the model or library associated with a node, double-click on it.
To pan the dependency graph, click and hold the left mouse button on an empty space then drag the mouse.
To zoom into and out of the region under the mouse pointer, use the mouse wheel.
To center the dependency graph and adjust the zoom so that the dependency graph fills the available space, press the space bar.
Please refer to the documentation for more information about all the features of the Dependency Viewer.
In the previous dependency graph, only one node exists for each model in the graph and at most one link exists from one node to another node. Therefore, this dependency graph does not show if multiple references exist from one model to another model. Furthermore, this view does not show which models are referenced in Normal mode and which models are referenced in Accelerator mode.
The dependency viewer can show referenced model instances, and this view can be accessed in one of two ways:
In the model, on the Modeling tab, select Compare > Dependencies > Referenced Model Instances.
From the Model Dependency Viewer, select Model Instances from the toolstrip.
Note that in this view, known as Instance View, libraries are never shown.
In Instance View, the gray nodes represent Simulink models. The directed lines indicate dependencies. Note: in this view two nodes are labeled sldemo_mdlref_F2C
because this model is referenced twice, once by sldemo_mdlref_outdoor_temp
and once by sldemo_mdlref_heater
. Except for the top model, all nodes have corners that denote the simulation mode of the referenced model. White corners denote a Normal mode reference and black corners denote an Accelerator mode reference. Thus, sldemo_mdlref_heater
makes a Normal mode reference to sldemo_mdlref_F2C
and an Accelerator mode reference to sldemo_mdlref_thermostat
.
Currently, the reference sldemo_mdlref_outdoor_temp
makes to sldemo_mdlref_F2C
is an Accelerator mode reference. Suppose you want to change this reference to be a Normal mode reference:
Select the node sldemo_mdlref_F2C
that sldemo_mdlref_outdoor_temp
points to.
Click Highlight Block. This opens sldemo_mdlref_outdoor_temp
and highlights the corresponding Model block.
Select the highlighted block.
In the Model Block tab, change the Simulation Mode to Normal
.
To see this change, go to the Model Dependency Viewer and click Refresh.
The Instance View dependency graph now looks like this:
The dependency viewer now shows the reference sldemo_mdlref_outdoor_temp
makes to sldemo_mdlref_F2C
as a Normal mode reference, but it has a round info badge on it. This badge appears because sldemo_mdlref_F2C
is configured to run in Normal mode but its parent, sldemo_mdlref_outdoor_temp
, is configured to run in Accelerator mode. Normal mode references from models running in Accelerator mode are not supported, so sldemo_mdlref_F2C
will run in Accelerator mode during simulation.
To make this model run in Normal mode, you must configure all of its ancestors to run in Normal mode. To do this:
Select the node sldemo_mdlref_outdoor_temp
.
Click Highlight Block. This opens sldemo_mdlref_depgraph
and highlights the corresponding Model block.
Select the highlighted block.
In the Model Block tab, change the Simulation Mode to Normal
. (If there were more Accelerator mode ancestors of sldemo_mdlref_F2C
, these would also need to be changed to Normal mode references.)
To see this change, go to the Model Dependency Viewer and click Refresh.
There are now two models that reference sldemo_mdlref_F2C
in Normal mode. After simulating this model, sl_demo_mdlref_heater
look likes this:
And sldemo_mdlref_outdoor_temp
looks like this:
The Model block that references sldemo_mdlref_F2C
in sldemo_mdlref_heater
has white corners, while the Model block that references sldemo_mdlref_F2C
in sldemo_mdlref_outdoor_temp
has gray corners. This is because Model block Normal Mode Visibility is on for the Model block in sldemo_mdlref_heater
but is not on for the Model block in sldemo_mdlref_outdoor_temp
. Note that only one Normal mode instance of each model will have white corners, the rest will have gray corners. Display blocks (for example, Scopes) will show data for the instance referenced from the Model block with white corners, in this case from the model sldemo_mdlref_heater
, but not for any other instance:
To open the Model Block Normal Mode Visibility dialog box, from the top model (sldemo_mdlref_depgraph
) in the Simulation tab, from the Prepare gallery, click Normal Mode Visibility. Select the instance of each model that is referenced more than once in Normal mode for which you want to have Normal Mode Visibility on.
Right now, no Model blocks have been selected, which means that during the last simulation, Simulink selected one instance of sldemo_mdlref_F2C
to have Normal Mode Visibility set to on, which was indicated by the Model block with white corners. To select the instance referenced by sldemo_mdlref_outdoor_temp
, check the check box corresponding to that instance, then press OK:
After changing the Normal Mode Visibility setting, simulate the model sldemo_mdlref_depgraph
to make use of the new setting.