Skip to content

nargin

Number of input arguments passed to the current function.

n = nargin

Inside a function body, returns the number of arguments the caller actually passed. Common for implementing optional parameters with defaults:

function y = foo(x, scale)
if nargin < 2; scale = 1.0; end
y = x * scale;
end
if nargin < 2; b = 10; end
  • nargout — Number of output arguments requested by the caller.
  • nargchk — Validate the number of input arguments.
  • inputname — Variable name of a function argument from the caller’s perspective.