263Implicit Parallelization (Vectorization and Indexing)
cellsize*ones(1,64/cellsize),...
cellsize*ones(1,64/cellsize));
end
r = p;
% Non-vectorized method
C1 = zeros(4,4,r,4,4,r);
for ir=1:4
for ic=1:4
for is=1:r
for jr=1:4
for jc=1:4
for js=1:r
temp = cellfun(@(x,y) x.*y, ...
bb(ir,ic,is), ...
bb(jr,jc,js), ...
'UniformOutput', false);
temp1 = cell2mat(temp);
temp2 = mean(temp1(:));
C1(ir,ic,is,jr,jc,js) = temp2; % 6-D
end
end
end
end
end
end
⇨ Elapsed time is 181.4119 seconds.
% Vectorized method (~3000x faster!)
mm = m/cellsize; % =4
nn = n/cellsize; % =4
b = reshape(cc, [cellsize mm cellsize nn p]);
b = permute(b, [1 3 2 4 5]); % 16 x 16 x 4 x 4 x 100
b = reshape(b, cellsize^2, [])/cellsize; ...