mustBeNonzeroLengthText
Checks that text is non-empty.
Category: Programming > Functions
Syntax
mustBeNonzeroLengthText(A)
Checks that A is text with at least one character. Returns nothing if the check passes and throws an error if not.
Description
mustBeNonzeroLengthText is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeNonzeroLengthText. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
A must be text (character vector, string array or cell array of character vectors) and every piece must have at least one character. An empty string or a cell holding '' fails.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Passing and failing input
mustBeNonzeroLengthText('abc');
disp('passed')
try
mustBeNonzeroLengthText('')
catch err
disp(err.message)
end
Output
passed
Value must be text with one or more characters.