Matlab中输入 help nargin
nargin Number of function input arguments.
Inside the body of a user-defined function, nargin returnsthe number of input arguments that were used to call the
function.
nargin(FUN) returns the number of declared inputs for the
M-file function FUN. The number of arguments is negative if the
function has a variable number of input arguments. FUN can be
a function handle that maps to a specific function, or a string
containing the name of that function.
注释:nargin是用来判断函数输入参数个数的,nargin返回的是调用函数时输入的参数个数,可以根据参数不同来进行不同的操作,例如:
function result=sum_operation(a,b)
if nargin==1
result=a;
else if nargin==2
result=a+b;
end