NARGIN Number of Input Arguments
Section: Functions and Scripts
narginfunction 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,
nargin, along with
isset can be used to determine
exactly what subset of the arguments were defined.
ExampleHere is a function that is declared to take five arguments, and that simply prints the value of
nargineach 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