Skip to content

nargout

Number of output arguments requested by the caller.

n = nargout

Inside a function body, returns how many output values the caller’s destructuring requested. Common for skipping expensive computations whose results aren’t going to be used:

function [m, idx] = costly(A)
m = ... % always compute
if nargout >= 2 % only compute idx if needed
idx = ...
end
end
if nargout > 1; computeOptional(); end
  • nargin — Number of input arguments passed to the current function.
  • nargoutchk — Validate the number of output arguments.