La traducción de esta página está obsoleta. Haga clic aquí para ver la última versión en inglés.
Definiciones de argumentos
Puesto que MATLAB® es un lenguaje sin tipificar, la mayoría de las funciones no requieren declaraciones o validación del argumento. Sin embargo, si la función tiene un uso amplio y necesita verificar el tipo, el tamaño u otros aspectos de las entradas para garantizar que el código funciona según lo previsto, puede definir un bloque de arguments
(desde la versión R2019b). Para obtener más detalles, consulte Function Argument Validation.
Además, puede comprobar cuántas entradas o salidas recibe la función, los nombres de las variables de entrada y mucho más.
Funciones
Temas
Valores de argumentos
- Ways to Parse Function Inputs
Choose a technique for checking the validity of input arguments. - Function Argument Validation
Declare input argument class and size and enforce restrictions on argument values.
- Check Function Inputs with validateattributes
This example shows how to verify that the inputs to your function conform to a set of requirements using thevalidateattributes
function. - Parse Function Inputs
Define required and optional inputs, assign defaults to optional inputs, and validate all inputs to a custom function using the Input Parser.
Número de argumentos
- Support Variable Number of Inputs
Define a function that accepts a variable number of input arguments usingvarargin
. Thevarargin
argument is a cell array that contains the function inputs, where each input is in its own cell. - Support Variable Number of Outputs
Define a function that returns a variable number of output arguments usingvarargout
. Outputvarargout
is a cell array that contains the function outputs, where each output is in its own cell. - Buscar el número de argumentos de funciones
Utilice
nargin
ynargout
para determinar cuántos argumentos de entrada o de salida recibe la función.
Ignorar entradas
- Ignorar entradas en definiciones de funciones
Si la función acepta un conjunto predefinido de entradas, pero no utiliza todas las entradas, utilice el operador de tilde (~
) para ignorarlas en la definición de función.