主要内容

matlab.metadata.Function Class

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

Describe function and its signature

Since R2026a

Description

The matlab.metadata.Function class provides information about a function, including its namespace, the path of its definition file, and its input and output arguments.

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

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

To create a matlab.metadata.Function object that describes a given function, call metafunction with the name of the function as a string.

mfunc = metafunction("functionName")

To create a Function object for a local function, call metafunction with the names of the main and local functions separated by >.

mfunc = metafunction("mainFunction>localFunction")

For more details and syntaxes, see metafunction.

Properties

expand all

Name of the function, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
private

Short description of the function, specified as a character vector. For user-defined functions, the text for this property comes from code comments in the function definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your functions, see Add Help for Your Program.

Attributes:

GetAccess
public
SetAccess
private

Detailed description of the function, specified as a character vector. For user-defined functions, the text for this property comes from code comments in the function definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your functions, see Add Help for Your Program.

Attributes:

GetAccess
public
SetAccess
private

The full path to the file that defines the function, specified as a character vector. For functions that are part of the MATLAB® executable, this property returns 'built-in'.

Attributes:

GetAccess
public
SetAccess
private

The name of the namespace the function is defined in, specified as a character vector. If the function is not a namespace function, the property returns an empty character vector.

Attributes:

GetAccess
public
SetAccess
private

Information about the function input and output arguments, specified as a matlab.metadata.CallSignature instance. The CallSignature instance contains information about the arguments and whether or not the function uses arguments blocks.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

Save the function pythagoreanTriple on your path.

function side3 = pythagoreanTriple(side1,side2)
% pythagoreanTriple  Check if two side lengths can form a Pythagorean triple
% If the two inputs can form a Pythagorean triple, the function returns the 
% third lengths. If no triple can be formed, the function returns -1.

    arguments (Input)
        side1 {mustBeInteger,mustBePositive}
        side2 {mustBeInteger,mustBePositive}
    end

    arguments (Output)
        side3 {mustBeInteger}
    end

    legleg = sqrt(side1^2 + side2^2);
    hypleg = sqrt(side1^2 - side2^2);
    leghyp = sqrt(side2^2 - side1^2);

    if (legleg == round(legleg)) && (legleg > 0)
        side3 = legleg;
    elseif (hypleg == round(hypleg)) && (hypleg > 0)
        side3 = hypleg;
    elseif (leghyp == round(leghyp)) && (leghyp > 0)
        side3 = leghyp;
    else 
        side3 = -1;
    end
end

To get information about the function using introspection, call metafunction to create a matlab.metadata.Function instance.

mf = metafunction("pythagoreanTriple")
mf = 

  Function with properties:

                   Name: 'pythagoreanTriple'
            Description: '  pythagoreanTriple  Check if two side lengths can form a Pythagorean triple'
    DetailedDescription: '  If the two inputs can form a Pythagorean triple, the function returns the 
                            third length. If no triple can be formed, the function returns -1.↵'
               FullPath: 'C:\functions\pythagoreanTriple.m'
          NamespaceName: ''
              Signature: [1×1 matlab.metadata.CallSignature]

Save the function file plotCircle.m on your path.

function plotCircle(r,x,y)
    arguments (Input)
        r {mustBePositive}
        x {mustBeNumeric} = 0
        y {mustBeNumeric} = 0
    end
    [xval,yval] = parametricCircle(r,x,y);
    plot(xval,yval)
    axis square
end

function [xout,yout] = parametricCircle(r,x,y)
    angle = linspace(0,2*pi);
    xout = r*cos(angle) + x;
    yout = r*sin(angle) + y;
end

To get information about parametricCircle using introspection, call metafunction to create a matlab.metadata.Function instance for the local function. The FullPath property shows that the plotCircle.m file contains the parametricCircle function.

mf = metafunction("plotCircle>parametricCircle")
mf = 

  Function with properties:

                   Name: 'parametricCircle'
            Description: ''
    DetailedDescription: ''
               FullPath: 'C:\functions\plotCircle.m'
          NamespaceName: ''
              Signature: [1×1 matlab.metadata.CallSignature]

Version History

Introduced in R2026a