主要内容

Access Function Metadata

Since R2026a

Function metadata is information about function definitions that you can access programmatically. This information includes:

  • Help text included in the function definition

  • The full path and namespace of the function

  • The type of validation applied to the input and output arguments of the function, including size, class, default values, and validation functions

Note

Introspection can only provide detailed information about arguments and validation when the function uses argument blocks. For functions that do not use argument blocks, the information available is limited.

Metadata for Functions

You can get function metadata programmatically by using the classes defined in the function metadata interface. Call metafunction with a function name to create an instance of matlab.metadata.Function. For example, define a function named twoStats.

function [m,s] = twoStats(data)
% Calculate mean and standard dev of input data.
    arguments
        data (1,:) {mustBeNumeric}
    end
    m = mean(data,"all");
    s = std(data,1,"all");
end

Call metafunction on twoStats to get a Function instance.

mf = metafunction("twoStats")
mf = 

Function with properties:

             Name: 'twoStats'
      Description: 'Calculate mean and standard dev of input data.'
    DetailedDescription: ''
               FullPath: 'C:\twoStats.m'
          NamespaceName: ''
              Signature: [1×1 matlab.metadata.CallSignature]

The Signature property of the Function instance provides the entry point for detailed metadata about the function arguments. For example, these classes provide specific information:

  • matlab.metadata.CallSignature — The Signature property of Function is of type CallSignature. The CallSignature class properties include arrays of matlab.metadata.Argument objects.

  • matlab.metadata.Argument — The Inputs and Outputs properties of CallSignature are of type Argument. The Argument class properties include information like whether an argument is required, the default value, and what validation is performed on the argument.

  • matlab.metadata.ArgumentValidation — The Validation property of Argument is of type ArgumentValidation. The ArgumentValidation class properties include information about class and size validation as well as any validator functions applied to the argument.

  • matlab.metadata.ArgumentValidator — The Functions property of ArgumentValidation is of type ArgumentValidator. The ArgumentValidator class properties describe a validation function applied to a given function argument.

For examples on how to access and use the data from these classes, see Check Function Compatibility Using Metadata. For a complete list of classes in the function metadata interface, see Function Introspection and Metadata.

Metadata for Class Methods

You can also call metafunction with a method name to create a Method instance. The matlab.metadata.Method class uses some of the function metadata classes to describe method arguments. (since R2026a) The Signature property of Method contains the same information as the Signature property of matlab.metadata.Function.

See Also

Topics