Mercurial > hg > ishara
annotate 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 |
rev | line source |
---|---|
samer@4 | 1 % scanl - scanl for cell arrays |
samer@4 | 2 % |
samer@4 | 3 % scanl :: |
samer@4 | 4 % (S,X->S) ~'scannning function', |
samer@4 | 5 % S ~'initial value', |
samer@4 | 6 % {[N]->X} ~'data to scan, sequence of length L' |
samer@4 | 7 % -> {[N]->S}. |
samer@4 | 8 |
samer@4 | 9 function Y=scanl(f,y,X,varargin) |
samer@4 | 10 Y=cell(size(X)); |
samer@4 | 11 if nargin>3 |
samer@4 | 12 opts=prefs('draw',0,varargin{:}); |
samer@4 | 13 for i=1:size(X,2) |
samer@4 | 14 y1=f(y,X{i}); |
samer@4 | 15 Y{i}=y1; |
samer@4 | 16 if opts.draw, opts.plotfn(i,y,X{i},y1); end |
samer@4 | 17 optpause(opts); |
samer@4 | 18 y=y1; |
samer@4 | 19 end |
samer@4 | 20 else |
samer@4 | 21 for i=1:size(X,2), y=f(y,X{i}); Y{i}=y; end |
samer@4 | 22 end |
samer@4 | 23 |
samer@4 | 24 |