nargout
- :
n =nargout()¶ - :
n =nargout(fcn)¶ Report how many output arguments are in play.
With no argument and evaluated inside a running function, return the number of results the caller has asked for, as determined by the assignment that invoked the function. This query is only meaningful inside a call: issuing it at the prompt is an error.
Given fcn—a function name as a string, or a handle—it instead returns that function’s declared output count. A function whose final output is varargout can produce an open-ended number of results, so the count is returned as a negative number whose magnitude minus one is the number of fixed outputs.
For instance, when
fis invoked asf ()
nargoutinsidefis 0, whereas[s, t] = f ()
makes it 2. Querying a named function behaves similarly:
nargout (@histc) # or nargout ("histc") using a string inputyields 2, since
histcdeclares two outputs, whilenargout (@imread)
yields −2, since
imreaddeclares one fixed output followed by varargout.Programming Note. An inline function reports 1, every anonymous function reports −1, and a built-in or .nxo function (no inspectable output list) reports −1 to match MATLAB R2026a.