Main Content

getReferencedModelNames

Class: coder.codedescriptor.CodeDescriptor
Namespace: coder.codedescriptor

Return names of referenced models

Syntax

refModels = getReferencedModelNames(codeDescObj)

Description

refModels = getReferencedModelNames(codeDescObj) returns a list of referenced models for a coder.codedescriptor.CodeDescriptor object. By default, the list includes only the unprotected models that the CodeDescriptor object directly references. For example, if model1 references model2 and model2 references model3, then running getReferencedModelNames from the model1 CodeDescriptor object returns only model2, not model3. To retrieve different lists of referenced models, use the optional IncludeAllLevels and IncludeProtectedModels parameters.

Input Arguments

expand all

coder.codedescriptor.CodeDescriptor object for which you want to retrieve the information about generated code.

Whether to return the full referenced model hierarchy, specified as true or false. If you set this parameter to true, the method recursively searches referenced models and returns the full referenced model hierarchy. If you set this parameter to false or do not specify a value, the method returns only the models that the top model directly references.

Whether to include protected models, specified as true or false. If you set this parameter to true, the method includes protected models in the list of referenced models. If you set this parameter to false or do not specify a value, the method excludes protected models from the list.

Output Arguments

expand all

A list of referenced models.

Examples

expand all

Open the model AsynchronousEventsTop.

openExample('AsynchronousEventsTop');

Build the model.

slbuild('AsynchronousEventsTop');

Create a coder.codedescriptor.CodeDescriptor object for the model.

codeDescObj = coder.getCodeDescriptor('AsynchronousEventsTop');

Get a list of referenced models included in the model.

getReferencedModelNames(codeDescObj)
ans =

  1×1 cell array
    {'AsynchronousEventsRef'}

Consider this model, myTopModel, that references a model, myMiddleModel.

Model that contains a reference to a model, myMiddleModel.

myMiddleModel contains a reference to another model, myBottomModel.

Model that contains a reference to a model, myBottomModel.

If you build myTopModel and use getReferencedModelNames without specifying the IncludeAllLevels parameter, the output includes only myMiddleModel.

model = "myTopModel";
slbuild(model);
codeDescObj = coder.getCodeDescriptor(model);
getReferencedModelNames(codeDescObj)
ans =

  1x1 cell array

    {'myMiddleModel'}

If you set the IncludeAllLevels parameter to true, the output also includes myBottomModel.

getReferencedModelNames(codeDescObj, IncludeAllLevels = true)
ans =

  2x1 cell array

    {'myMiddleModel'}
    {'myBottomModel'}

Consider this model, myTopModel, that references a protected model, myProtectedModel.

Model that contains a model reference of a protected model, myProtectedModel.

If you build the model and use getReferencedModelNames without specifying the IncludeProtectedModels parameter, the output is empty.

model = "myTopModel";
slbuild(model);
codeDescObj = coder.getCodeDescriptor(model);
getReferencedModelNames(codeDescObj)
ans =

  0x1 empty cell array

If you set the IncludeProtectedModels parameter to true, the output includes myProtectedModel.

getReferencedModelNames(codeDescObj, IncludeProtectedModels = true)
ans =

  1x1 cell array

    {'myProtectedModel'}

Version History

Introduced in R2018a