annotate general/arrutils/forels.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 |
fbc0540a9208 |
children |
|
rev |
line source |
samer@4
|
1 % forels - do an action for each element of an array in order
|
samer@4
|
2 %
|
samer@4
|
3 % forels ::
|
samer@4
|
4 % (A->action) ~'action to apply to each element',
|
samer@4
|
5 % [[Size]->A] ~'array of elements of type',
|
samer@13
|
6 % options iterate_options
|
samer@13
|
7 % => void.
|
samer@4
|
8 %
|
samer@4
|
9 % Note, the array can be multidimensional - the standard order
|
samer@4
|
10 % cycles through the earlier indices before the later ones, eg
|
samer@4
|
11 % rows, then columns, then slices etc.
|
samer@4
|
12
|
samer@13
|
13 function forels(f,X,varargin)
|
samer@4
|
14 N=numel(X);
|
samer@4
|
15 iterate(@g,1,varargin{:});
|
samer@4
|
16
|
samer@4
|
17 function i=g(i)
|
samer@4
|
18 if i>N, i=[]; else f(X(i)); i=i+1; end
|
samer@4
|
19 end
|
samer@4
|
20 end
|