メインコンテンツ

matlab.metadata.ArgumentValidation Class

Namespace: matlab.metadata

Describe validation for function argument

Since R2026a

Description

The matlab.metadata.ArgumentValidation class provides information about the validation for an input or output argument of a function or method. The class includes information about class and size validation and any validation functions applied to the argument.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

You cannot instantiate a matlab.metadata.ArgumentValidation object directly. The Validation property of matlab.metadata.Argument is of type ArgumentValidation.

Properties

expand all

The class validation applied to an argument, specified as a matlab.metadata.Class instance. If an argument does not use class validation, the property value is an empty array.

Attributes:

GetAccess
public
SetAccess
private

Size validation applied to an argument, specified as a matlab.metadata.ArrayDimension array. If an argument does not use size validation, the property value is an empty array.

Attributes:

GetAccess
public
SetAccess
private

Validation functions applied to an argument, specified as a matlab.metadata.ArgumentValidator array. If an argument does not use validation functions, the property value is an empty array.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

Save the function plotEllipse on your path.

function plotEllipse(a,b,center,lineOpts)
% plotEllipse  Plot an ellipse
% Plots an ellipse using the inputs a and b as the semi-major
% and semi-minor axes. center is an optional input that specifies
% the coordinates of the center of the ellipse. Specify Color and 
% LineStyle as optional name-value arguments. 

    arguments (Input)
        a {mustBeNumeric,mustBePositive}
        b {mustBeNumeric,mustBePositive}
        center (1,2) {mustBeNumeric} = [0 0]
        lineOpts.Color {mustBeTextScalar} = "black"
        lineOpts.LineStyle {mustBeTextScalar} = "-"
    end
    
    angle = linspace(0,2*pi);
    xval = a*cos(angle) + center(1);
    yval = b*sin(angle) + center(2);

    plot(xval,yval,Color=lineOpts.Color,LineStyle=lineOpts.LineStyle)
    axis equal
end

To get information about the function using introspection, call metafunction to create a matlab.metadata.Function instance for plotEllipse. Access the Signature property of the result. The property shows that the function has five input arguments and uses an input arguments block.

mf = metafunction("plotEllipse");
ms = mf.Signature
ms = 

  CallSignature with properties:

                 Inputs: [1×5 matlab.metadata.Argument]
                Outputs: [1×0 matlab.metadata.Argument]
     HasInputValidation: 1
    HasOutputValidation: 0

Access the Validation property of the third input argument. The metadata shows that the input argument has both size and function validators.

mv = ms.Inputs(3).Validation
mv = 

  ArgumentValidation with properties:

        Class: [0×0 matlab.metadata.Class]
         Size: [1×2 matlab.metadata.FixedDimension]
    Functions: [1×1 matlab.metadata.ArgumentValidator]

Confirm that the size validator has two fixed dimensions, (1,2).

mv.Size.Length
ans =

  uint64

   1


ans =

  uint64

   2

Version History

Introduced in R2026a