Main Content

Definition von Argumenten

Eine variable Anzahl von Eingaben oder Ausgaben akzeptieren, auf gültige Werte prüfen

Da MATLAB® eine schwach typisierte Sprache ist, erfordern die meisten Funktionen keine Argumentdeklarationen oder -validierung. Wenn Ihre Funktion jedoch breit genutzt wird und Sie den Typ, die Größe oder andere Aspekte von Eingaben überprüfen möchten, um sicherzustellen, dass Ihr Code wie erwartet funktioniert, können Sie einen arguments-Block definieren (seit R2019b). Weitere Informationen finden Sie unter Function Argument Validation.

Zusätzlich können Sie prüfen, wie viele Eingaben oder Ausgaben Ihre Funktion empfängt, die Namen der Eingabevariablen und mehr.

Funktionen

alle erweitern

Argument-Block

argumentsDeclare function argument validation (Seit R2019b)

Validieren von numerischen Werten

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
mustBeSparseValidate that value is sparse (Seit R2023b)
mustBeRealValidate that value is real
mustBeIntegerValidate that value is integer
mustBeNonmissingValidate that value is not missing (Seit R2020b)

Vergleiche

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

Datentypen

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

Größe

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

Bereichs- und Satz-Zugehörigkeit

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

Namen

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

Name-Wert-Argumentstruktur

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

Eingaben

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

Ausgaben

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 (Seit R2020b)
inputnameVariable name of function input
mfilenameFilename of currently running code
inputParserInput parser for functions

Themen

Validierung von Argumenten

Anzahl von Argumenten

Ignorierte Eingaben

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