When used within a function, nargin
gives the number of parameters passed to that function. Used with a string argument fn
it is an in-built function, which returns the number of parameters taken by function fn
. You should not call it without a parameter from the workspace:
nargin returns the number of input arguments passed in the call to the currently executing function. Use this nargin syntax only in the body of a function.
You can, but you should avoid assigning a value to nargin
, since it will then loose the second semantics:
nargin('sparse')
ans =
6
nargin = 0;
nargin('sparse')
Index exceeds matrix dimensions.