Main Content


Validate that value is text with nonzero length

Since R2020b



mustBeNonzeroLengthText(value) throws an error if value does not have at least one character in each element or if the input is not text. This function does not return a value.


collapse all

Create an empty string named txt. Call mustBeNonzeroLengthText with txt as an input. mustBeNonzeroLengthText throws an error since the variable is a piece of text with zero length.

txt = "";
Value must be text with one or more characters.

Use mustBeNonzeroLengthText to restrict the input argument values that are accepted by a function. You can accomplish this by adding an arguments block to the function that validates the input arguments

This function restricts the value of the argument nonzeroLengthText to nonzero length text values.

function MyFunction(nonzeroLengthText)
      nonzeroLengthText {mustBeNonzeroLengthText}

Call the function. MATLAB® calls mustBeNonzeroLengthText on the value being assigned to the argument. mustBeNonzeroLengthText issues an error because the value "" is not text with one or more characters.

Error using MyFunction
Invalid argument at position 1. Value must be text with one or more characters.

Input Arguments

collapse all

Value to validate, specified as a scalar or array. If value is not a string array, character array, or cell array of character vectors with at least one character in each element, nonzeroLengthText will throw an error.

Example: nonzeroLengthText('foo')

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2020b