samer@47: function varargout=plotseq(F,X,varargin) samer@47: % plotseq - use arbitrary function to plot elements of sequence sequence samer@47: % samer@47: % plotseq :: samer@47: % (A->handle) ~'function to make a plot', samer@47: % seq A ~'data sequence to plot', samer@47: % options { samer@47: % ppre :: action unit ~'called before each plot'; samer@47: % ppost :: action unit ~'called after eacn plot'; samer@47: % mode :: {'gui','immed','null'} ~ samer@47: % 'Controls how the iteration proceeds. samer@47: % gui: obtain next plot by clicking on title samer@47: % immed: use function ITERATE to loop immediately samer@47: % null: do nothing but return state fn and initial state' samer@47: % } samer@47: % -> (plotseq_state -> plotseq_state) ~'state transformer', samer@47: % plotseq_state ~'initial state. samer@47: % samer@47: % This works best (at all?) if the plotting function draws in one axes. samer@47: % The axes gains a clickable suffix to it's title. Button 1 click advances samer@47: % to the next object in the data sequence. Button 2 click rewinds to the samer@47: % beginning of the sequence. Alternatively the space bar advances and samer@47: % 'b' rewinds. samer@47: samer@47: samer@47: opts=prefs('mode','gui','ppre',@nop,'ppost',@nop,varargin{:}); samer@47: samer@47: fig=getparam(opts,'fig',gcf); samer@47: figure(fig); ax=gca; hold off; samer@47: fn=@nextplot; samer@47: S0.i=1; S0.X=X; samer@47: switch opts.mode samer@47: case 'immed', iterate(fn,S0,opts); samer@47: case 'gui', samer@47: disp('Click TITLE or [space] for next, button 2 click or [b] to rewind.'); samer@47: rotate3d off; samer@47: zoom off; pan off; samer@47: iterate_gui(fn,S0,opts); samer@47: end samer@47: samer@47: if nargout==1, varargout{1}={fn,S0}; else varargout={fn,S0}; end samer@47: samer@47: samer@47: % state machine to control output samer@47: % 2nd return is handle of object to respond to mouse click for next/rewind samer@47: function [S,ti]=nextplot(S) samer@47: axes(ax); samer@47: opts.ppre(); samer@47: F(head(S.X)); samer@47: ti=get(gca,'Title'); samer@47: set(ti,'String',sprintf('%s (%d)',get(ti,'String'),S.i)); samer@47: opts.ppost(); samer@47: samer@47: S.i=S.i+1; samer@47: S.X=next(S.X); samer@47: if isempty(S.X), S=[]; end samer@47: end samer@47: end % of main function samer@47: