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.
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 = "";
mustBeNonzeroLengthText(txt)
Value must be text with one or more characters.
Restrict Argument Values
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)
arguments
nonzeroLengthText {mustBeNonzeroLengthText}endend
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.
MyFunction("")
Error using MyFunction (line 3)
MyFunction("")
^^
Invalid argument at position 1. Value must be text with one or more characters.
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™.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.