samer@39: % ge - collect outputs from function into cell array samer@39: % samer@39: % ge :: (A{:}=>B{1:N}), M:[N] -> (A{:}=>cell {B{1:M}}). samer@39: % samer@39: % f>=N is a function which takes the same arguments as f samer@39: % but collects the first N return values into a cell array. samer@39: % eg feval(@eig>=2,X) returns the eigenvalues and eigenvectors samer@39: % of X in a two-element cell array. samer@39: samer@38: function g=ge(f,nout) samer@39: % if nargin<2, nout=nargout(f); end samer@39: % if nout<0, error('function must have a definite number of outputs'); end samer@38: if nargin(f)==1, g=@h1; else g=@hn; end samer@38: function rets=h1(x), [rets{1:nout}]=f(x); end samer@38: function rets=hn(varargin), [rets{1:nout}]=f(varargin{:}); end samer@38: end