annotate general/cellutils/@cell/scanl.m @ 13:03694e5c8365
Reorganised some high order list functions to correct class-based method dispatch; fixed some docs.
author |
samer |
date |
Wed, 16 Jan 2013 12:12:34 +0000 |
parents |
45aaf9b2d7b0 |
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
|