主要内容

matlab.metadata.DefaultArgumentValue Class

Namespace: matlab.metadata

Describe default value of function or method argument

Since R2026a

Description

The matlab.metadata.DefaultArgumentValue class describes the default value assigned to a function or method argument.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

You cannot instantiate a matlab.metadata.DefaultArgumentValue object directly. The DefaultValue property of matlab.metadata.Argument is of type DefaultArgumentValue.

Properties

expand all

The expression for the default value, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
private

Arguments that are referenced by the expression for the default value, specified as a matlab.metadata.ArgumentIdentifier array. If the expression does not reference any arguments, the property value is an empty array.

Attributes:

GetAccess
public
SetAccess
private

Methods

expand all

Examples

collapse all

Save the function plotArc on your path.

function plotArc(r,arcLength)
% plotArc  Plot an arc of a circle based on the radius and length of
% the arc. By default, the function plots a full circle.

    arguments (Input)
        r {mustBePositive}
        arcLength = r*2*pi
    end
    
    angle = linspace(0,arcLength/r);
    xval = r*cos(angle);
    yval = r*sin(angle);

    plot(xval,yval)
    axis equal
end

To get information about the function using introspection, call metafunction to create a matlab.metadata.Function instance for plotArc. Access the matlab.metadata.Argument instance for the second input argument, arcLength.

mf = metafunction("plotArc");
ma = mf.Signature.Inputs(2)
ma = 

  Argument with properties:

             Identifier: arcLength
            Description: ''
    DetailedDescription: ''
               Required: 0
              Repeating: 0
              NameValue: 0
             Validation: [0×0 matlab.metadata.ArgumentValidation]
           DefaultValue: [1×1 matlab.metadata.DefaultArgumentValue]
            SourceClass: [0×0 matlab.metadata.Class]

Access the DefaultValue property. The DefaultArgumentValue instance shows the expression for the default value as a character vector, and it indicates that the default value expression references argument r.

mdf = ma.DefaultValue
mdf = 

  DefaultArgumentValue with properties:

             Expression: 'r*2*pi'
    ReferencedArguments: r

Use the evaluate method to find the default value of arcLength when r is 2.

evaluate(mdf,2)
ans =

   12.5664

Version History

Introduced in R2026a