How to sum 3D arrays in a 1x3 cell?

3 views (last 30 days)
Joseph
Joseph on 20 Jul 2018
Edited: Joseph on 20 Jul 2018
Hi all,
Thanks in advance for your help. So:
I have a 1x1 cell array that consists of 3 arrays of size 1366x9x1333, 1366x9x1332, 1366x9x1332. However, these arrays were generated from a cross-correlation function with an increasing lag (from 1-3) and so the number of time points from the initial image is 3999. More specifically, if we, for example, assume a lag of 3, the cross correlation function is called and calculated the cross correlation between the 1,4,7,10... lines and then the 2,5,8,11...lines and then the 3,6,9,12....lines. I'd like to combine these three arrays along the third dimension so that we regain the original number of points (3999) and the points are returned to the order: 1,2,3,4,5,6,7,8,9...
Is there a way to do this?

Accepted Answer

Guillaume
Guillaume on 20 Jul 2018
If I understood correctly you want to interlace the pages:
%Assuming cell array is 1x3, not 1x1 as you wrote:
numpages = sum(cellfun(@(m) size(m, 3), yourcellarray));
fullarray = zeros(size(yourcellarray{1}, 1), size(yourcellarray{1}), 2), numpages);
fullarray(:, :, 1:3:end) = yourcellarray{1};
fullarray(:, :, 2:3:end) = yourcellarray{2};
fullarray(:, :, 3:3:end) = yourcellarray{3};
would be one way.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!