Main Content

Class Metadata

What Is Class Metadata?

Class metadata is information about class definitions that is available from various metaclasses objects. Use metaclass objects to obtain information without having to create instances of the class. Metadata enables the programmatic inspection of classes. Each metaclass has properties, methods, and events that contain information about the class or class component it describes.

All class components have an associated metaclass, which you access from the meta.class object. For example, create the meta.class object for the matlab.alias.AliasFileManager class:

mc = ?matlab.alias.AliasFileManager
mc = 

  class with properties:

                     Name: 'matlab.alias.AliasFileManager'
              Description: 'AliasFileManager Create and edit alias definition files'
      DetailedDescription: '  Use an AliasFileManager object to create and manage...
                   Hidden: 0
                   Sealed: 1
                 Abstract: 0
              Enumeration: 0
          ConstructOnLoad: 0
         HandleCompatible: 1
          InferiorClasses: {0×1 cell}
        ContainingPackage: [1×1 meta.package]
                  Aliases: [0×1 string]
     RestrictsSubclassing: 1
             PropertyList: [1×1]
               MethodList: [28×1 meta.method]
                EventList: [1×1 meta.event]
    EnumerationMemberList: [0×1 meta.EnumeratedValue]
           SuperclassList: [1×1 meta.class]

The meta Package

The meta package contains metaclasses that describe the definition of classes and class components. The class name indicates the component described by the metaclass. For example, each class property has a associated with it. Attributes defined for class components correspond to properties in the respective metaclass object.

Metaclass Objects

You cannot instantiate metaclasses directly by calling the respective class constructor. Create metaclass objects from class instances or from the class name.

  • ?ClassName — Returns a meta.class object for the named class. Use meta.class.fromName with class names stored as characters in variables.

  • meta.class.fromName('ClassName') — returns the meta.class object for the named class (meta.class.fromName is a meta.class method).

  • metaclass(obj) — Returns a metaclass object for the class instance (metaclass)

Create meta.class object from class name using the ? operator:

mc = ?MyClass;

Create meta.class object from class name using the fromName method:

mc = meta.class.fromName('MyClass');

Create meta.class object from class instance

obj = MyClass;
mc = metaclass(obj);

The metaclass function returns the meta.class object (that is, an object of the meta.class class). You can obtain other metaclass objects (, meta.method, and so on) from the meta.class object.


Metaclass is a term used here to refer to all the classes in the meta package. meta.class is a class in the meta package whose instances contain information about MATLAB® classes. Metadata is information about classes contained in metaclasses.

Metaclass Object Lifecycle

When you change a class definition, MATLAB reloads the class definition. If instances of the class exist, MATLAB updates those objects according to the new definition.

However, MATLAB does not update existing metaclass objects to the new class definition. If you change a class definition while metaclass objects of that class exist, MATLAB deletes the metaclass objects and their handles become invalid. You must create a new metaclass object after updating the class.

For information on how to modify and reload classes, see Automatic Updates for Modified Classes.

Related Topics