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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.