info.m
function result_func= info(msg) function res_func =wrap(func) function varargout = inner_wrap(varargin) varargout= num2cell(zeros(1,nargout)); disp(['start ',msg]) [varargout{:}] = func(varargin{:}); disp(['end ',msg]) end res_func = @inner_wrap; end result_func = @wrap; end
ff.m
function varargout = ff(varargin) disp('run ff'); for i=1:length(varargin) varargout{i} = varargin{i} + 1; end end
测试代码
g=info('func'); h=g(@ff); a=h(1) [a,b]=h(2,3) [a,b,c]=h(3,4,5)