Return the nth output argument of the function specified by the function handle or string func.
Any additional arguments are passed directly to func. The total number of arguments to call func with can be passed in ntot; by default ntot is n. The input n can also be a vector of indices of the output, in which case the output will be a cell array of the requested output arguments.
The intended use nthargout
is to avoid intermediate variables. For
example, when finding the indices of the maximum entry of a matrix, the
following two compositions of nthargout
m = magic (5); cell2mat (nthargout ([1, 2], @ind2sub, size (m), nthargout (2, @max, m(:)))) ⇒ 5 3
are completely equivalent to the following lines:
m = magic (5); [~, idx] = max (M(:)); [i, j] = ind2sub (size (m), idx); [i, j] ⇒ 5 3
It can also be helpful to have all output arguments in a single cell in the following manner:
USV = nthargout ([1:3], @svd, hilb (5));
See also: nargin, nargout, varargin, varargout, isargout.
Package: octave