annotate general/cellutils/cellzip.m @ 4:e44f49929e56
Adding reorganised general toolbox, now in several subdirectories.
author |
samer |
date |
Sat, 12 Jan 2013 19:21:22 +0000 |
parents |
|
children |
47cb292350f3 |
rev |
line source |
samer@4
|
1 function Y=cellzip(fn,varargin)
|
samer@4
|
2 % cellzip - Zip cell arrays with a function
|
samer@4
|
3 %
|
samer@4
|
4 % cellzip :: (
|
samer@4
|
5 % (D1,...,Dn)->R ~ function of n arguments,
|
samer@4
|
6 % {[size]->D1}, ..., {[size]->Dn} ~ n cell arrays of appropriate types
|
samer@4
|
7 % ) -> {[size]->R} ~ cell array of results
|
samer@4
|
8
|
samer@4
|
9 % preallocate to fix size
|
samer@4
|
10 sizes=cellmap(@size,varargin);
|
samer@4
|
11 sz=sizes{1};
|
samer@4
|
12 for i=1:nargin-1
|
samer@4
|
13 if ~all(sizes{i}==sz), error('Sizes do not match'); end
|
samer@4
|
14 end
|
samer@4
|
15
|
samer@4
|
16 Y=cell(sz);
|
samer@4
|
17
|
samer@4
|
18 for i=1:prod(sz)
|
samer@4
|
19 args=cellmap(@(c)c{i},varargin);
|
samer@4
|
20 Y{i}=feval(fn,args{:});
|
samer@4
|
21 end
|
samer@4
|
22
|
samer@4
|
23
|