% ge - collect outputs from function into cell array
%
% ge :: (A{:}=>B{1:N}), M:[N] -> (A{:}=>cell {B{1:M}}).
%
% f>=N is a function which takes the same arguments as f
% but collects the first N return values into a cell array.
% eg feval(@eig>=2,X) returns the eigenvalues and eigenvectors
% of X in a two-element cell array.

function g=ge(f,nout)
%	if nargin<2, nout=nargout(f); end
%	if nout<0, error('function must have a definite number of outputs'); end
	if nargin(f)==1, g=@h1; else g=@hn; end
	function rets=h1(x), [rets{1:nout}]=f(x); end
	function rets=hn(varargin), [rets{1:nout}]=f(varargin{:}); end
end
