Access Function Metadata
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— TheSignatureproperty ofFunctionis of typeCallSignature. TheCallSignatureclass properties include arrays ofmatlab.metadata.Argumentobjects.matlab.metadata.Argument— TheInputsandOutputsproperties ofCallSignatureare of typeArgument. TheArgumentclass properties include information like whether an argument is required, the default value, and what validation is performed on the argument.matlab.metadata.ArgumentValidation— TheValidationproperty ofArgumentis of typeArgumentValidation. TheArgumentValidationclass properties include information about class and size validation as well as any validator functions applied to the argument.matlab.metadata.ArgumentValidator— TheFunctionsproperty ofArgumentValidationis of typeArgumentValidator. TheArgumentValidatorclass 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.