validateattributes(A, classes, attributes)
validateattributes(A, classes, attributes, argIndex)
validateattributes(A, classes, attributes, funcName)
validateattributes(A, classes, attributes, funcName, varName)
validateattributes(A, classes, attributes, funcName, varName, argIndex)
| Parameter | Description |
|---|---|
| A | array or object to validate. |
| classes | accepted class names, specified as a character vector, string array, or cell array of character vectors. |
| attributes | required attributes, specified as a cell array or string array. Attributes that require a value must be followed immediately by that value. |
| argIndex | positive integer used in generated error messages to identify the argument position. |
| funcName | function name used in generated error identifiers. |
| varName | variable name used in generated error messages. |
validateattributes raises an error if A does not belong to at least one requested class or does not satisfy all requested attributes. The function returns no output when validation succeeds.
classes accepts concrete class names and custom class names tested with isa. The aliases numeric, integer, and float are also supported. numeric accepts numeric arrays, integer accepts integer storage classes, and float accepts double or single arrays.
Supported shape attributes are 2d, 3d, column, row, scalar, scalartext, vector, square, diag, nonempty, and nonsparse.
Supported valued size attributes are size, numel, ncols, nrows, and ndims. For size, use NaN in an expected dimension to skip that dimension.
Supported value attributes are finite, nonnan, binary, even, odd, integer, real, nonnegative, nonpositive, negative, nonzero, and positive.
Supported range attributes are >, >=, <, and <=. The comparison value must follow the attribute name.
Supported monotonicity attributes are decreasing, increasing, nondecreasing, and nonincreasing. Monotonicity is checked down each column.
validateattributes([1 2 3], {'numeric'}, {'row', 'vector', 'positive'})
A = ones(2, 3, 4);
validateattributes(A, {'numeric'}, {'3d', 'size', [2 NaN 4], 'ndims', 3})
A = [1 4; 2 4; 3 5];
validateattributes(A, {'numeric'}, {'nondecreasing'})
p = inputParser();
addRequired(p, 'name', @(x) validateattributes(x, {'char'}, {'nonempty'}));
addOptional(p, 'id', 1, @(x) validateattributes(x, {'numeric'}, {'scalar', 'positive'}));
parse(p, 'item', 3);
p.Results
| Version | Description |
|---|---|
| 1.0.0 | initial version |