mustBeVector
Checks that a value is a vector.
Category: Programming > Functions
Syntax
mustBeVector(A)
Checks that A is a row or column vector. Returns nothing if the check passes and throws an error if not.
Description
mustBeVector is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeVector. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
A 1-by-n or n-by-1 array passes, including a scalar. Matrices and higher-dimensional arrays fail.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Passing and failing input
mustBeVector([1 2 3]);
disp('passed')
try
mustBeVector([1 2; 3 4])
catch err
disp(err.message)
end
Output
passed
Value must be a 1-by-n vector or an n-by-1 vector.