Skip to content

__nthargout__

miscellaneous · scripts/miscellaneous/__nthargout__.m

: v = nthargout (n, fcn, …)
: v = nthargout (n, ntot, fcn, …)

Call fcn with the remaining arguments and return its output number n.

fcn is a function handle or the name of a function. Normally fcn is asked for just as many outputs as the largest n; the optional ntot fixes the number of outputs requested, which matters for functions whose result depends on it, for example size.

When n is a vector the result is a cell array holding the requested outputs in the order of n.

nthargout (2, @max, [1 5 3])
   ⇒ 2
nthargout (1:2, @max, [1 5 3])
   ⇒ {5, 2}