mustBeTextScalar
Checks that a value is a single piece of text.
Category: Programming > Functions
Syntax
mustBeTextScalar(A)
Checks that A is one character vector or one string. Returns nothing if the check passes and throws an error if not.
Description
mustBeTextScalar is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeTextScalar. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
A character row vector or a 1-by-1 string array passes. Cell arrays and multi-element string arrays fail.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Passing and failing input
mustBeTextScalar("hello");
disp('passed')
try
mustBeTextScalar({'a'})
catch err
disp(err.message)
end
Output
passed
Value must be a character vector or string scalar.