Main Content

pathsToReferencedModel

Model hierarchy path composed of referenced models and Model blocks

Since R2023b

Description

example

[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.

Examples

collapse all

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.

openProject("ModelReferenceHierarchy");

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.

topmodel = "sldemo_mdlref_depgraph";
refmodel = "sldemo_mdlref_F2C";
[models,blocks] = pathsToReferencedModel(topmodel,refmodel)
models = 4x1 cell
    {'sldemo_mdlref_depgraph'    }
    {'sldemo_mdlref_outdoor_temp'}
    {'sldemo_mdlref_heater'      }
    {'sldemo_mdlref_F2C'         }

blocks = 
  1x2 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.

blocks(1)
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 character vectors from this object.

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.

blocks(2)
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 character vectors from this object.

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.

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