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.
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 (line 3)
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.
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
The
mustBeText function fully supports GPU arrays.
To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more
information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
You can accelerate your code by running the mustBeText function on a
GPU. GPU computing requires Parallel Computing Toolbox™.
You can scale up your code by running the mustBeText function with
distributed arrays, enabling you to leverage the combined memory of a compute cluster. Using
distributed arrays requires Parallel Computing Toolbox.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.