Report the number of output arguments from a function.
Called from within a function, return the number of values the caller
expects to receive. At the top level, nargout
with no argument is
undefined and will produce an error.
If called with the optional argument fcn—a function name or handle—return the number of declared output values that the function can produce.
If the final output argument is varargout the returned value is negative.
For example,
f ()
will cause nargout
to return 0 inside the function f
and
[s, t] = f ()
will cause nargout
to return 2 inside the function f
.
In the second usage,
nargout (@histc) # or nargout ("histc") using a string input
will return 2, because histc
has two outputs, whereas
nargout (@imread)
will return -2, because imread
has two outputs and the second is
varargout.
Programming Note. nargout
does not work for built-in functions and
returns -1 for all anonymous functions.
See also: nargin, varargout, isargout, nthargout.
Package: octave