samer@47
|
1 function varargout=plotseq(F,X,varargin)
|
samer@47
|
2 % plotseq - use arbitrary function to plot elements of sequence sequence
|
samer@47
|
3 %
|
samer@47
|
4 % plotseq ::
|
samer@47
|
5 % (A->handle) ~'function to make a plot',
|
samer@47
|
6 % seq A ~'data sequence to plot',
|
samer@47
|
7 % options {
|
samer@47
|
8 % ppre :: action unit ~'called before each plot';
|
samer@47
|
9 % ppost :: action unit ~'called after eacn plot';
|
samer@47
|
10 % mode :: {'gui','immed','null'} ~
|
samer@47
|
11 % 'Controls how the iteration proceeds.
|
samer@47
|
12 % gui: obtain next plot by clicking on title
|
samer@47
|
13 % immed: use function ITERATE to loop immediately
|
samer@47
|
14 % null: do nothing but return state fn and initial state'
|
samer@47
|
15 % }
|
samer@47
|
16 % -> (plotseq_state -> plotseq_state) ~'state transformer',
|
samer@47
|
17 % plotseq_state ~'initial state.
|
samer@47
|
18 %
|
samer@47
|
19 % This works best (at all?) if the plotting function draws in one axes.
|
samer@47
|
20 % The axes gains a clickable suffix to it's title. Button 1 click advances
|
samer@47
|
21 % to the next object in the data sequence. Button 2 click rewinds to the
|
samer@47
|
22 % beginning of the sequence. Alternatively the space bar advances and
|
samer@47
|
23 % 'b' rewinds.
|
samer@47
|
24
|
samer@47
|
25
|
samer@47
|
26 opts=prefs('mode','gui','ppre',@nop,'ppost',@nop,varargin{:});
|
samer@47
|
27
|
samer@47
|
28 fig=getparam(opts,'fig',gcf);
|
samer@47
|
29 figure(fig); ax=gca; hold off;
|
samer@47
|
30 fn=@nextplot;
|
samer@47
|
31 S0.i=1; S0.X=X;
|
samer@47
|
32 switch opts.mode
|
samer@47
|
33 case 'immed', iterate(fn,S0,opts);
|
samer@47
|
34 case 'gui',
|
samer@47
|
35 disp('Click TITLE or [space] for next, button 2 click or [b] to rewind.');
|
samer@47
|
36 rotate3d off;
|
samer@47
|
37 zoom off; pan off;
|
samer@47
|
38 iterate_gui(fn,S0,opts);
|
samer@47
|
39 end
|
samer@47
|
40
|
samer@47
|
41 if nargout==1, varargout{1}={fn,S0}; else varargout={fn,S0}; end
|
samer@47
|
42
|
samer@47
|
43
|
samer@47
|
44 % state machine to control output
|
samer@47
|
45 % 2nd return is handle of object to respond to mouse click for next/rewind
|
samer@47
|
46 function [S,ti]=nextplot(S)
|
samer@47
|
47 axes(ax);
|
samer@47
|
48 opts.ppre();
|
samer@47
|
49 F(head(S.X));
|
samer@47
|
50 ti=get(gca,'Title');
|
samer@47
|
51 set(ti,'String',sprintf('%s (%d)',get(ti,'String'),S.i));
|
samer@47
|
52 opts.ppost();
|
samer@47
|
53
|
samer@47
|
54 S.i=S.i+1;
|
samer@47
|
55 S.X=next(S.X);
|
samer@47
|
56 if isempty(S.X), S=[]; end
|
samer@47
|
57 end
|
samer@47
|
58 end % of main function
|
samer@47
|
59
|