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.
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.
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.