MATLAB Function Reference Previous page   Next Page
nargin, nargout

Return number of function arguments

Syntax

Description

In the body of a function M-file, nargin and nargout indicate how many input or output arguments, respectively, a user has supplied. Outside the body of a function M-file, nargin and nargout indicate the number of input or output arguments, respectively, for a given function. The number of arguments is negative if the function has a variable number of arguments.

nargin returns the number of input arguments specified for a function.

nargin(fun) returns the number of declared inputs for the function fun or -1 if the function has a variable number of input arguments. fun may be the name of a function, or a function handle that maps to a specific function.

nargout returns the number of output arguments specified for a function.

nargout(fun) returns the number of declared outputs for the function fun. fun may be the name of a function, or a function handle that maps to a specific function.

Examples

This example shows portions of the code for a function called myplot, which accepts an optional number of input and output arguments:

See Also

inputname, varargin, varargout, nargchk, nargoutchk


Previous page  nargchk nargoutchk Next page

© 1994-2005 The MathWorks, Inc.