Mercurial > hg > ishara
annotate general/cellutils/cellzip.m @ 53:3ba80c9914ff
Minor doc fix, added .class to .hgignore
author | samer |
---|---|
date | Mon, 02 Feb 2015 10:47:55 +0000 |
parents | 47cb292350f3 |
children |
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@7 | 20 Y{i}=fn(args{:}); |
samer@4 | 21 end |
samer@4 | 22 |
samer@4 | 23 |