mustBeText(value) throws an error if
value is not a string array, character vector, or cell array of
character vectors. An empty 0x0 char array '', empty string
"", and missing strings are special cases that also counts as text.
This function does not return a value.
Create an array of numbers notText, and then use
mustBeText to validate the value. mustBeText
throws an error since the array does not contain text.
notText = [1 2 3];
mustBeText(notText)
Value must be a character vector, string array, or cell array of character vectors.
Restrict Argument Values
Use mustBeText 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 textInput to
text values.
function MyFunction(textInput)
arguments
textInput {mustBeText}endend
Call the function with a numeric input argument. MATLAB® calls mustBeText on the value being assigned to the
argument. mustBeText issues an error because the value
2 is not text.
MyFunction(2)
Error using MyFunction
MyFunction(2)
↑
Invalid argument at position 1. Value must be a character vector, string array, or cell array of character vectors.
Value to validate, specified as a scalar or array. If value, is
not a string scalar or array, character array, or cell array of character vectors
mustBeText will throw an error.
Example: mustBeText('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.