Skip to content

nargin

builtin · libnexusinterp/nexus-value/ov-usr-fcn-proprietary.cc

: n = nargin ()
: n = nargin (fcn)

Report how many input arguments are in play.

With no argument and evaluated inside a running function, return the count of arguments the caller actually supplied for the current invocation. Evaluated at the prompt, it reports the number of arguments handed to the interpreter on its command line.

Given fcn—the name of a function as a string, or a handle to one—it instead returns that function’s declared input-parameter count rather than any live call count. When the function’s parameter list ends in varargin, the declared count cannot be exact, so the result is returned as a negative number: its magnitude minus one is the number of fixed parameters. For a set operation declared as

function [y, ia, ib] = union (a, b, varargin)

the query

nargin ("union")
⇒  -3

reports −3, i.e. two fixed inputs plus a trailing varargin.

An unknown function name or a fcn that is neither a string nor a handle raises an error. Built-in and dynamically loaded .nxo targets have no inspectable parameter list; matching MATLAB R2026a, those queries return −1 rather than erroring. Passing more than one argument is also an error.