mustBeText

Checks that a value is text: characters, a string array or a cell array of character vectors.

Category: Programming > Functions

Syntax

mustBeText(A)

Checks that A is text. Returns nothing if the check passes and throws an error if not.

Description

mustBeText is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeText. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.

Accepted are character vectors, string arrays and cell arrays whose cells all hold character vectors. An empty cell array passes. Any other class fails.

Input arguments

A
The value to check. Any array of the class the validator accepts.

Example

Passing and failing input

mustBeText({'a', 'b'});
disp('passed')
try
    mustBeText(42)
catch err
    disp(err.message)
end
Output
passed
Value must be a character vector, string array, or cell array of character vectors.

See also

mustBeTextScalar mustBeNonzeroLengthText ischar isstring