Main Content

可视化模型参考层次结构

This example shows how to view, explore, and analyze model dependencies using the Dependency Analyzer. It shows how to find referenced models and interact with the dependency graph.

Open Model

Open the example modelsldemo_mdlref_depgraph, which contains multiple referenced models in a model hierarchy.

Find Referenced Models

Use thefind_mdlrefsfunction to programmatically find referenced models and Model blocks. For example, enter this command in the MATLAB Command Window:

[refMdls, modelBlks] = find_mdlrefs('sldemo_mdlref_depgraph')

find_mdlrefsreturns two cell arrays,refMdlsandmodelBlks.refMdlscontains the names of all models that are directly or indirectly referenced bysldemo_mdlref_depgraph. By default, the last element inrefMdlsis the name of the input model.modelBlkscontains block paths for all Model blocks in the top model and all referenced models.

View Model Reference Dependency Graph

To view the dependency graph for thesldemo_mdlref_depgraphmodel, perform one of these actions to open the Dependency Analyzer for a model:

  • Use thedepviewfunction.

  • In theModelingtab, in theDesignsection, clickDependency Analyzer.

In the dependency graph, the boxes represent Simulink models. The arrows indicate dependencies. For example, the link fromsldemo_mdlref_depgraphtosldemo_mdlref_houseindicates thatsldemo_mdlref_depgraph参考文献sldemo_mdlref_house. If the model references libraries, subsystems, or protected models, the dependency graph shows them in the hierarchy.

In this view, only one box exists for each model in the graph and at most one arrow exists from one box to another box. The dependency graph does not show if multiple references exist from one model to another model. This view does not show which models are referenced in normal mode and which models are referenced in accelerator mode.

Interact with Dependency Graph

  • To select a box, click it.

  • To open the model or library associated with a box, double-click it.

  • To pan the dependency graph, click and hold the mouse wheel button then drag the mouse.

  • To zoom in and out, 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.

View Model Instances Dependency Graph

To view the referenced model instances in the dependency graph, perform one of these actions:

  • Usedepview('sldemo_mdlref_depgraph','ModelReferenceInstance',true).

  • From the Dependency Analyzer, in theViewssection, selectModel Instances.

In the instance view, the boxes represent Simulink models. The arrows indicate dependencies. The dependency graph shows when multiple references exist from one model to another model. In the instance view, libraries are never shown.

In this view two boxes are labeledsldemo_mdlref_F2Cbecause this model is referenced twice, once bysldemo_mdlref_outdoor_tempand once bysldemo_mdlref_heater. The top model is colored in blue. The red color denotes a normal mode reference, and the yellow color denotes an accelerator mode reference.

sldemo_mdlref_heatermakes a normal mode reference tosldemo_mdlref_F2Cand an accelerator mode reference tosldemo_mdlref_thermostat.

Explore Model Instance Views

Currently, the referencesldemo_mdlref_outdoor_tempmakes tosldemo_mdlref_F2Cis an accelerator mode reference. Suppose you want to change this reference to be a normal mode reference:

  1. Select the arrow linkingsldemo_mdlref_outdoor_temptosldemo_mdlref_F2C.

  2. In thePropertiespane on the right, in the dependency table, clickFahrenheit to Celsius. Simulink opens the modelsldemo_mdlref_outdoor_tempand highlights the Model block namedFahrenheit to Celsius. This Model block referencessldemo_mdlref_F2C.

  3. Select the Model block namedFahrenheit to Celsius.

  4. In theModel Blocktab, change theSimulation ModetoNormal.

  5. 看到这种变化,去德pendency graph and clickAnalyze.

The dependency graph now shows the referencesldemo_mdlref_outdoor_tempmakes tosldemo_mdlref_F2Cas a Normal Mode (Overridden) reference. Note thatsldemo_mdlref_F2Cis 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, sosldemo_mdlref_F2Cwill 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:

  1. Select the arrow linkingsldemo_mdlref_depgraphtosldemo_mdlref_outdoor_temp.

  2. In thePropertiespane on the right, in the dependency table, clickoutdoor temp. Simulink opens the modelsldemo_mdlref_depgraphand highlights the Model block namedoutdoor temp. This Model block referencessldemo_mdlref_outdoor_temp.

  3. Select the Model block namedoutdoor temp.

  4. In theModel Blocktab, change theSimulation ModetoNormal. (If there were more accelerator mode ancestors ofsldemo_mdlref_F2C, these would also need to be changed to normal mode references.)

  5. 看到这种变化,去德pendency graph and clickAnalyze.

Related Topics