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 Version Information Properties.

FileFormatMinorVersion

Contains a value only for a Service Pack release of Simulink®. Indicates that the file was saved by a Service Pack release, when the Service Pack included changes to the model file format.

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

Name of release of Simulink that was used to save the model file, for example, 'R2016a'.

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'