nargout
Number of output arguments
Usage
nargout
- It returns the number of output arguments supplied by the user when the function is called.
- It has to be called within the function body.
nargout(name)
- It returns the maximum number of output arguments expected by the function named
fname.
- It returns -1 if there can be unlimited number of output arguments.
- The
.m file of the function should be located in the current work folder.
nargout(h)
h is a function handle.
- It returns the maximum number of output arguments expected by the function associated with
h.
- It returns -1 if there can be unlimited number of output arguments.
- For function handle of an anonymous function, it always return -1.
Examples
- User-defined function
f is given below, which requires 2 output arguments.
function [a,b] = f(c,d,e)
disp('Number of output arguments required:')
nargout
a = c;
b = d;
Running a = f(1,2,3); gives the following output.
Output
Number of output arguments given:
ans =
1.0000
f is the function defined in the example above.
nargout('f')
Output
ans =
2.000