Main Content

La traduzione di questa pagina non è aggiornata. Fai clic qui per vedere l'ultima versione in inglese.

Definizioni degli argomenti

Accettare un numero variabile di input o output, verificare che i valori siano validi

Poiché MATLAB® è un linguaggio non tipizzato, la maggior parte delle funzioni non richiede la dichiarazione o la convalida degli argomenti. Tuttavia, se la funzione è molto utilizzata e occorre verificare il tipo, la dimensione o altri aspetti degli input per garantire che il codice funzioni come previsto, è possibile definire un blocco arguments (dalla release R2019b). Per maggiori informazioni, consultare Function Argument Validation.

Inoltre, è possibile verificare quanti input o output riceve la funzione, i nomi delle variabili di input e altro ancora.

Funzioni

espandi tutto

Blocco degli argomenti

argumentsDeclare function argument validation (Da R2019b)

Convalida dei valori numerici

mustBePositiveValidate that value is positive
mustBeNonpositiveValidate that value is nonpositive
mustBeNonnegativeValidate that value is nonnegative
mustBeNegativeValidate that value is negative
mustBeFiniteValidate that value is finite
mustBeNonNanValidate that value is not NaN
mustBeNonzeroValidate that value is nonzero
mustBeNonsparseValidate that value is nonsparse
mustBeRealValidate that value is real
mustBeIntegerValidate that value is integer
mustBeNonmissingValidate that value is not missing (Da R2020b)

Confronti

mustBeGreaterThanValidate that value is greater than another value
mustBeLessThanValidate that value is less than another value
mustBeGreaterThanOrEqualValidate that value is greater than or equal to another value
mustBeLessThanOrEqualValidate that value is less than or equal to another value

Tipi di dati

mustBeAValidate that value comes from one of specified classes (Da R2020b)
mustBeNumericValidate that value is numeric
mustBeNumericOrLogicalValidate that value is numeric or logical
mustBeFloatValidate that value is floating-point array (Da R2020b)
mustBeTextValidate that value is string array, character vector, or cell array of character vectors (Da R2020b)
mustBeTextScalarValidate that value is single piece of text (Da R2020b)
mustBeNonzeroLengthTextValidate that value is text with nonzero length (Da R2020b)
mustBeUnderlyingTypeValidate that value has specified underlying type (Da R2020b)

Dimensione

mustBeNonemptyValidate that value is nonempty
mustBeScalarOrEmptyValidate that value is scalar or empty (Da R2020b)
mustBeVectorValidate that value is vector (Da R2020b)

Appartenenza all’intervallo o all’insieme

mustBeInRangeValidate that value is in the specified range (Da R2020b)
mustBeMemberValidate that value is member of specified set

Nomi

mustBeFileValidate that path refers to file (Da R2020b)
mustBeFolderValidate that input path refers to folder (Da R2020b)
mustBeValidVariableNameValidate that input name is valid variable name (Da R2020b)

Struttura degli argomenti nome-valore

namedargs2cellConvert structure containing name-value pairs to cell array (Da R2019b)

Input

vararginVariable-length input argument list
narginNumber of function input arguments
narginchkValidate number of input arguments

Output

varargoutVariable-length output argument list
nargoutNumber of function output arguments
nargoutchkValidate number of output arguments
validateattributesCheck validity of array
validatestringCheck validity of text
validatecolorValidate color values (Da R2020b)
inputnameVariable name of function input
mfilenameFilename of currently running code
inputParserInput parser for functions

Argomenti

Convalida dell’argomento

Numero di argomenti

Input passanti

  • Ignore Inputs in Function Definitions
    If your function accepts a predefined set of inputs, but does not use all the inputs, use the tilde (~) operator to ignore them in your function definition.