Mercurial > hg > ishara
comparison general/funutils/scanl.m @ 4:e44f49929e56
Adding reorganised general toolbox, now in several subdirectories.
author | samer |
---|---|
date | Sat, 12 Jan 2013 19:21:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:3f77126f7b5f | 4:e44f49929e56 |
---|---|
1 % scanl - scanl for cell arrays | |
2 % | |
3 % scanl :: | |
4 % (S,X->S) ~'scannning function', | |
5 % S ~'initial value', | |
6 % {[N]->X} ~'data to scan, sequence of length L' | |
7 % -> {[N]->S}. | |
8 | |
9 function Y=scanl(f,y,X,varargin) | |
10 Y=cell(size(X)); | |
11 if nargin>3 | |
12 opts=prefs('draw',0,varargin{:}); | |
13 for i=1:size(X,2) | |
14 y1=f(y,X{i}); | |
15 Y{i}=y1; | |
16 if opts.draw, opts.plotfn(i,y,X{i},y1); end | |
17 optpause(opts); | |
18 y=y1; | |
19 end | |
20 else | |
21 for i=1:size(X,2), y=f(y,X{i}); Y{i}=y; end | |
22 end | |
23 | |
24 |