FreeMat
NARGIN Number of Input Arguments

Section: Functions and Scripts

Usage

The nargin function returns the number of arguments passed to a function when it was called. The general syntax for its use is

  y = nargin

FreeMat allows for fewer arguments to be passed to a function than were declared, and nargin, along with isset can be used to determine exactly what subset of the arguments were defined.

You can also use nargin on a function handle to return the number of input arguments expected by the function

  y = nargin(fun)

where fun is the name of the function (e.g. 'sin') or a function handle.

Example

Here is a function that is declared to take five arguments, and that simply prints the value of nargin each time it is called.

     nargintest.m
function nargintest(a1,a2,a3,a4,a5)
  printf('nargin = %d\n',nargin);
--> nargintest(3);
nargin = 1
--> nargintest(3,'h');
nargin = 2
--> nargintest(3,'h',1.34);
nargin = 3
--> nargintest(3,'h',1.34,pi,e);
nargin = 5
--> nargin('sin')

ans = 
 1 

--> y = @sin

y = 
 @sin
--> nargin(y)

ans = 
 1