Main Content

matlab.metadata.Class Class

Namespace: matlab.metadata
Superclasses: matlab.metadata.MetaData

Describe MATLAB class

Renamed from meta.class in R2024a

Description

The matlab.metadata.Class class provides a way to get descriptive information about MATLAB® classes. By creating a matlab.metadata.Class object for a specific class, you can get information about the class definition.

matlab.metadata.Class properties contain lists of properties, methods, events, and class attributes set in the classdef line, as well as other information about how the class is defined.

You cannot set the values of matlab.metadata.Class object properties. You can only query the properties.

Create a matlab.metadata.Class object from an instance of a class or using the class name using these options:

  • metaclass(obj) returns a matlab.metadata.Class object representing the object passed as an argument.

  • ?ClassName returns a matlab.metadata.Class object representing the named class.

  • matlab.metadata.Class.fromName("ClassName") is a static method that returns a matlab.metadata.Class object representing the named class.

You cannot instantiate a matlab.metadata.Class object directly by calling its constructor.

The matlab.metadata.Class class is a handle class.

Class Attributes

Abstract
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Create a matlab.metadata.Class object from an instance of a class or using the class name using these options:

  • metaclass(obj) returns a matlab.metadata.Class object representing the object passed as an argument.

  • ?ClassName returns a matlab.metadata.Class object representing the named class.

  • matlab.metadata.Class.fromName("ClassName") is a static method that returns a matlab.metadata.Class object representing the named class.

You cannot instantiate a matlab.metadata.Class object directly.

Properties

expand all

Name of the class, returned as a character vector. The name returned by this property includes the class namespace.

Short description of the class, returned as a character vector. For user-defined classes, the text for this property comes from comments in the class definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your classes, see Custom Help Text.

Detailed description of the class, returned as a character vector. For user-defined classes, the text for this property comes from comments in the class definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your classes, see Custom Help Text.

Is class hidden from inspection tools, returned as logical true or false. If true, the class does not appear in the output of MATLAB commands or tools that display class names. However, you can access the class programmatically.

Data Types: logical

Value of class attribute Sealed, returned as a logical value. If Sealed is true, this class cannot be subclassed.

Data Types: logical

Value of class attribute Abstract, returned as a logical value. The value of this property is true if the class or any property or method has its Abstract attribute set to true. For information on abstract classes, see Abstract Classes and Class Members.

Data Types: logical

Is class an enumeration class, returned as a logical value. If true, this class is an enumeration class. For more information about enumeration classes, see Define Enumeration Classes.

Data Types: logical

Value of class attribute ConstructOnLoad, returned as a logical value. If true, MATLAB calls the class constructor automatically when loading an object from a MAT-file. To enable ConstructOnLoad, the constructor must support being called with no input arguments. For more information, see Default Save and Load Process for Objects.

Data Types: logical

Value of class attribute HandleCompatible, returned as a logical value. If true, this class is a handle-compatible class. For more information about handle-compatible classes, see Handle Compatible Classes.

Value of class attribute InferiorClasses, returned as a matlab.metadata.Class object array. For information on class precedence, see Class Precedence.

Namespace containing the class, returned as a matlab.metadata.Namespace object. If the class is not in a namespace, this property contains an empty matlab.metadata.Namespace object. For more information about namespaces, see Create Namespaces.

List of aliases defined for the class, returned as a string array. The aliases are listed from oldest to newest.

Does class restrict subclassing, returned as a logical true or false. MATLAB sets this property to true when the class restricts subclassing by:

  • Setting the Sealed attribute to true

  • Specifying the classes that can subclass this class using the AllowedSubclasses attribute

For more information restricting subclassing, see Specify Allowed Subclasses.

Properties defined for the class, returned as an array of matlab.metadata.Property objects. The matlab.metadata.Property objects describe each property defined by this class, including all inherited public and protected properties. For more information on properties, see Properties.

Methods defined for the class, returned as an array of matlab.metadata.Method objects. The matlab.metadata.Method objects describe each method defined by this class, including inherited public and protected methods. For more information on methods, see Methods in Class Design.

Events defined for the class, including all inherited events, returned as an array of matlab.metadata.Event objects. Only handle classes can define events so this property is an empty matlab.metadata.Event object for value classes. All handle classes inherit the ObjectBeingDestroyed event. For more information about events, see Events.

Name and hidden status for enumeration members, returned as an array of matlab.metadata.EnumerationMember objects. Access the Name and Hidden properties of the corresponding member matlab.metadata.EnumerationMember object to obtain information. For more information, see Enumerations.

Direct superclasses of this class, returned as an array of matlab.metadata.Class objects. The matlab.metadata.Class objects describe each direct superclass from which this class derives. For more information on subclassing, see Subclass Definition.

Methods

expand all

Events

Event NameTriggerEvent DataEvent Attributes
InstanceCreated

This event occurs every time an instance of the class described by the matlab.metadata.Class is created.

The event occurs immediately after all constructor functions finish executing.

event.ClassInstanceEvent

NotifyAccess: private

ListenAccess: public

InstanceDestroyed

This event occurs every time an instance of the class described by the matlab.metadata.Class is destroyed.

The event occurs immediately before any destructor functions execute.

event.ClassInstanceEvent

NotifyAccess: private

ListenAccess: public

Examples

collapse all

Use introspection to get inheritance information about the IntrospectionExample class.

classdef IntrospectionExample
    % IntrospectionExample  Performs basic functions on two numbers
    % Class methods find the sum and product of its properties.
    properties
        % a  First property
        % First of two numeric properties
        a {mustBeNumeric} = 0
        
        % b  Second property
        % Second of two numeric properties
        b {mustBeNumeric} = 0
    end
    
    methods
        function sum = addNumbers(obj)
            % addNumbers  Sum the properties
            %   Finds the sum of properties a and b.
            sum = obj.a + obj.b;
        end
        function prod = multNumbers(obj)
            % multNumbers  Multiply the properties
            %   Finds the product of properties a and b.
            prod = obj.a*obj.b;
        end
    end
end

Create a metaclass instance for IntrospectionExample.

mc = ?IntrospectionExample
mc = 

  Class with properties:

                    Name: 'IntrospectionExample'
             Description: 'Performs basic functions on two numbers'
     DetailedDescription: '  Class methods find the sum and product of its properties.'
                  Hidden: 0
                  Sealed: 0
                Abstract: 0
             Enumeration: 0
         ConstructOnLoad: 0
        HandleCompatible: 0
         InferiorClasses: [0×1 matlab.metadata.Class]
               Namespace: [0×0 matlab.metadata.Namespace]
                 Aliases: [0×1 string]
    RestrictsSubclassing: 0
            PropertyList: [2×1 matlab.metadata.Property]
              MethodList: [4×1 matlab.metadata.Method]
               EventList: [0×1 matlab.metadata.Event]
   EnumerationMemberList: [0×1 matlab.metadata.EnumerationMember]
          SuperclassList: [0×1 matlab.metadata.Class]


The property summary for IntrospectionExample shows there are four methods described in the MethodList property. Access the MethodList property of mc and display the names of all four class methods.

for i = 1:4
mc.MethodList(i).Name
end
ans = 
'multNumbers'
ans = 
'addNumbers'
ans = 
'IntrospectionExample'
ans = 
'empty'

Version History

Introduced in R2008a

expand all