annotate general/funutils/foldcols.m @ 9:45aaf9b2d7b0
Moved high-order sequence/list functions to @cell class.
author |
samer |
date |
Mon, 14 Jan 2013 15:49:04 +0000 |
parents |
e44f49929e56 |
children |
|
rev |
line source |
samer@4
|
1 % foldcols - fold from left combinator for columns of an array
|
samer@4
|
2 %
|
samer@4
|
3 % foldcols :;
|
samer@4
|
4 % (A,[[N]]->A) ~'folding function',
|
samer@4
|
5 % A ~'initial value',
|
samer@4
|
6 % [[N,L]] ~'data to scan, sequence of length L'
|
samer@4
|
7 % -> A.
|
samer@4
|
8
|
samer@4
|
9 function y=foldcols(f,y,X,varargin)
|
samer@4
|
10 if nargin>3
|
samer@4
|
11 opts=prefs('draw',0,varargin{:});
|
samer@4
|
12 for i=1:size(X,2)
|
samer@4
|
13 y1=f(y,X(:,i));
|
samer@4
|
14 if opts.draw
|
samer@4
|
15 opts.plotfn(i,y,X(:,i),y1);
|
samer@4
|
16 end
|
samer@4
|
17 optpause(opts);
|
samer@4
|
18 y=y1;
|
samer@4
|
19 end
|
samer@4
|
20 else % streamlined version
|
samer@4
|
21 for i=1:size(X,2), y=f(y,X(:,i)); end
|
samer@4
|
22 end
|
samer@4
|
23
|
samer@4
|
24
|