samer@47: function varargout=animdata(upd,X,varargin) samer@47: % animdata - use arbitrary function to animate data sequence samer@47: % samer@47: % animdata :: samer@47: % A->unit ~'function to update animation', samer@47: % seq A ~'data sequence to plot', samer@47: % options { samer@47: % pre :: action / @nop ~'called before each plot'; samer@47: % post :: action / @nop ~'called after eacn plot'; samer@47: % defer :: bool / 0 ~'if 1, just return state transformer function'; samer@47: % fps :: nonneg / 0 ~'if positive, used timed iterator at this rate' samer@47: % } samer@47: % -> (A->A,handle) ~'action to iterate', samer@47: % A ~'initial state'. samer@47: samer@47: samer@47: samer@47: opts=prefs('fps',0,'pre',@nop,'post',@nop,'defer',0,varargin{:}); samer@47: samer@47: if opts.defer, samer@47: stfn=@plotnext_h; samer@47: elseif opts.fps>0 samer@47: stfn=@plotnext; samer@47: API=iterate_timed(stfn,X,1/opts.fps,opts); samer@47: if nargout==1, varargout{1}=API; end samer@47: else samer@47: stfn=@plotnext; samer@47: iterate(stfn,X,opts); samer@47: if nargout==1, varargout{1}={stfn,X}; else varargout={stfn,X}; end samer@47: end samer@47: samer@47: samer@47: function S=plotnext(S), upd(head(S)); S=next(S); end samer@47: function [S,h]=plotnext_h(S), samer@47: upd(head(S)); S=next(S); samer@47: if nargout>1, h=get(gca,'title'); end samer@47: end samer@47: end samer@47: samer@47: