Simulink.MDLInfo class

Package: Simulink
Superclasses:

Extract model file information without loading block diagram into memory

Description

The class Simulink.MDLInfo extracts information from a model file without loading the block diagram into memory.

You can create an MdlInfo object containing all the model information properties, or you can use the static methods for convenient access to individual properties without creating the class first. For example, to get the description only:

description = Simulink.MDLInfo.getDescription('mymodel')

To get the metadata only:

metadata = Simulink.MDLInfo.getMetadata('mymodel')

All model information properties are read only.

Construction

info = Simulink.MDLInfo('mymodel') creates an instance of the MdlInfo class info and populates the properties with the information from the model file 'mymodel'.

mymodel can be:

  • A block diagram name (for example, vdp)

  • The file name for a file on the MATLAB® path (for example, mymodel.slx)

  • A file name relative to the current folder (for example, mydir/mymodel.slx)

  • A fully qualified file name (for example, C:\mydir\mymodel.slx)

Simulink.MDLInfo resolves the supplied name by looking at files on the MATLAB path, and ignores any block diagrams in memory. This may cause unexpected results if you supply the name of a loaded model, but its file is shadowed by another file on the MATLAB path. If a file is shadowed, you see a warning in the command window. To avoid any confusion, supply a fully-qualified file name to Simulink.MDLInfo.

Properties

BlockDiagramName

Name of block diagram.

BlockDiagramType

Type of block diagram. For example, 'Model', Subsystem', 'Library'.

Description

The Description parameter of the model. For details, see Access Model Information Programmatically.

ReleaseUpdateLevel

Contains the update release number that was used to save the SLX model. It is zero if the SLX model was saved in a general release, for example, 'R2020a'. It is a positive integer if the SLX model was saved in an update release, for example, 2 if the model was saved in 'R2020a Update 2'.

It is zero for MDL files and for SLX files saved in releases before R2020a.

FileName

The fully-qualified Name of the model file.

Interface

Names and attributes of the block diagram's root inports, outports, model references, etc., describing the graphical interface if you created a Model Reference block from this model.

Structure.

IsLibrary

Whether the block diagram is a library. Logical.

LastModifiedBy

Name of the user who last saved the model.

LastSavedArchitecture

Platform architecture when saved, for example, 'glnxa64'.

Metadata

Names and values of arbitrary data associated with the model.

Structure. The structure fields can be character vectors, numeric matrices of type "double", or more structures. Use the method getMetadata to extract this metadata structure without loading the model.

ModelVersion

Model file version number.

ReleaseName

Release name that was used to save the model file, for example, 'R2020a'.

SavedCharacterEncoding

Character encoding when saved, for example, 'UTF-8'.

SimulinkVersion

Version number of Simulink® software that was used to save the model file.

Methods

getDescriptionExtract model file description without loading block diagram into memory
getMetadataExtract model file metadata without loading block diagram into memory

Copy Semantics

Handle. To learn how this affects your use of the class, see Copying Objects (MATLAB) in the MATLAB Programming Fundamentals documentation.

Examples

Construct and view a model information object:

info = Simulink.MDLInfo('mymodel')
% Get the Version when the model was saved
simulink_version = info.SimulinkVersion; 
% Get model metadata
metadata = info.metadata

To add metadata to a model, create a metadata structure containing the information you require and use set_param to attach it to the model. For example:

  metadata.TestStatus = 'untested';
  metadata.ExpectedCompletionDate
     = '01/01/2011';
  load_system(mymodelname);
  set_param(mymodelname,'Metadata',...
  metadata)  % must be a struct
  save_system(mymodelname);
  close_system(mymodelname);

Construct a model information object for a model named mpowertrain, in order to find the names of referenced models without loading the model into memory:

info = Simulink.MDLInfo('mpowertrain')
% Get the Interface property
info.Interface

Output:

ans = 
                   Inports: [0x1 struct]
                  Outports: [0x1 struct]
                 Trigports: [0x1 struct]
                 Connports: [0x1 struct]
              ModelVersion: '1.122'
           ModelReferences: {2x1 cell}
    ParameterArgumentNames: ''
        TestPointedSignals: [0x1 struct]

Get the referenced models:

 info.Interface.ModelReferences

Output is in the form model name / block path | referenced model name:

ans = 
    'mpowertrain/Model Variants|manual_transmission'
    'mpowertrain/engine model|menginemodel'