主要内容

pathsToReferencedModel

R2026b

Model hierarchy path composed of referenced models and Model blocks

Since R2023b

Description

[models,blocks] = pathsToReferencedModel(topModel,refModel) finds all referenced models and Model blocks in a model hierarchy starting at the specified top model and ending at the specified referenced model.

This function uses the find_mdlrefs function with default options to populate the model hierarchy.

example

Examples

collapse all

Open a project that contains a model hierarchy.

openExample("simulink/VisualizeModelReferenceHierarchiesExample")

Get the paths to the referenced model in terms of models and Model blocks.

topmodel = "sldemo_mdlref_depgraph";
refmodel = "sldemo_mdlref_F2C";
[models,blocks] = pathsToReferencedModel(topmodel,refmodel)
models =

  4×1 cell array

    {'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 lists the models along the path from the specified top model to the specified referenced model.

The returned blocks array includes one Simulink.BlockPath object for each Model block that references the specified model. The size of the array indicates the number of times the model hierarchy references the model. In this example, the specified referenced model appears twice in the model hierarchy.

Each Simulink.BlockPath object provides a fully specified block path for a Model block that references the specified model.

blocks(1)
ans = 

  Simulink.BlockPath
  Package: Simulink

  Block Path:
    sldemo_mdlref_depgraph/outdoor temp
      sldemo_mdlref_outdoor_temp/Fahrenheit to Celsius

Each hierarchical Model block path is given relative to its parent model. The last Model block path references the specified model.

Input Arguments

collapse all

Name of top model, specified as a character vector or string scalar.

Data Types: char | string

Name of referenced model, specified as a character vector or string scalar.

Data Types: char | string

Output Arguments

collapse all

Models in path, returned as a cell array of character vectors.

The array includes the model name as a character vector for:

  • The specified top model

  • Each model between the specified top model and the specified referenced model

  • The specified referenced model

Model blocks in path, returned as an array of Simulink.BlockPath objects.

Each Model block between the specified top model and the specified referenced model is identified by a Simulink.BlockPath object.

Version History

Introduced in R2023b