This example shows how to view dependencies among referenced models.
During 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:
find_mdlrefs utility function to find all Model blocks and all models referenced by a model. Type
help find_mdlrefs for more information about this function.
[refMdls, modelBlks] = find_mdlrefs('sldemo_mdlref_depgraph');
find_mdlrefs returns two cell arrays,
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.
Double click on the blue box in the example model to view its model reference dependency graph. In general, use the
view_mdlrefs utility function or select the menu item Analysis > Model Dependencies > Model Dependency Viewer > Models Only to start the dependency viewer for a specific model.
The next figure shows the dependency graph of
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_house indicates that
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.
Left-clicking on a node selects it.
Double-clicking on a node opens the associated model or library.
Pressing the left mouse button on an empty space and then dragging the mouse pans the dependency graph.
The mouse wheel can be used to zoom into and out of the region currently under the mouse pointer.
Pressing the space bar centers the dependency graph and adjusts the zoom so that the dependency graph fits in the available space.
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:
From the model, select the menu item Analysis > Model Dependencies > Model Dependency Viewer > Referenced Model Instances
From the model dependency viewer, select Model Instances from the toolstrip.
Note that in this view, which we refer to 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
Currently, the reference
sldemo_mdlref_outdoor_temp makes to
sldemo_mdlref_F2C is an Accelerator mode reference. Hovering the mouse over the node
sldemo_mdlref_outdoor_temp references displays a tooltip showing the path to the block making the reference to
sldemo_mdlref_outdoor_temp. Suppose you want to change this to be a Normal mode reference:
Left-click on the node
sldemo_mdlref_outdoor_temp points to.
Select Highlight Block from the toolstrip; this opens
sldemo_mdlref_outdoor_temp and highlight the corresponding Model block.
Right click on the highlighted block.
Select Block Parameters (ModelReference) from the menu that appears.
Change the Simulation mode to Normal, and click OK.
To see this change in the dependency viewer, go to the dependency viewer and select Refresh from the toolstrip.
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, click on the node
sldemo_mdlref_outdoor_temp and select Highlight Block from the toolstrip; this opens
sldemo_mdlref_depgraph and highlights the corresponding Model block. Right click on the highlighted block, select Block Parameters (ModelReference), change the Simulation mode to Normal, and click OK. (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 in the dependency viewer, go to the dependency viewer and select Refresh from the toolstrip:
There are now two models that reference
sldemo_mdlref_F2C in Normal mode. After simulating this model,
sl_demo_mdlref_heater look likes this:
sldemo_mdlref_outdoor_temp looks like this:
The Model block that references
sldemo_mdlref_heater has white corners, while the Model block that references
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) select Diagram > Subsystem & Model Reference > Model Block 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 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.