view general/funutils/@function_handle/ge.m @ 39:c388f1c70669

Updated documentation and fixed some bugs in function algebra
author samer
date Tue, 29 Jan 2013 17:02:00 +0000
parents 9d24b616bb06
children
line wrap: on
line source
% 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