以下是引用wangjunying在2006-4-21 14:07:00的发言:
nargin是什么意思?有什么作用呢?
请朋友们赐教!
Number of function arguments
Syntax
n = nargin
n = nargin('fun')
n = nargout
n = nargout('fun')
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 M-file function fun or -1 if the function has a variable of input arguments.
nargout returns the number of output arguments specified for a function.
nargout('fun') returns the number of declared outputs for the M-file function fun.
Examples
This example shows portions of the code for a function called myplot, which accepts an optional number of input and output arguments:
function [x0,y0] = myplot(fname,lims,npts,angl,subdiv)
% MYPLOT Plot a function.
% MYPLOT(fname,lims,npts,angl,subdiv)
% The first two input arguments are
% required; the other three have default values.
...
if nargin < 5, subdiv = 20; end
if nargin < 4, angl = 10; end
if nargin < 3, npts = 25; end
...
if nargout == 0
plot(x,y)
else
x0 = x;
y0 = y;
end
See Also
inputname, nargchk
[此贴子已经被作者于2006-4-21 21:53:12编辑过]