MATLAB: How to sum over 3 dimensional cell array, where each cell also contains cells

3 dimensionalcellMATLABsum

I have a 6x6x645 cell array, call it cellArray. So for each element i, where , of cellArray(:,:,i) we have a 6×6 cell. Each of these 6×6 cells themselves have 1×3 double matrices at every entry. For example for i=5:
cellArray(:,:,5) =
{1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double}
{1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double}
{1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double}
{1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double}
{1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double}
{1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double} {1×3 double}
These 1×3 matrices are confindence intervals with [lowerbound,estimate,upperbound]. My goal is to sum all the confidence intervals over the 645 cells such that we are left with one 6×6 cell containing 1×3 matrices with the sums of all the intervals. How do you sum over this?

Best Answer

I'm tempted to ask how this data got to be a cell array, when it should really have been a 3x6x6x645 numeric array. We can fix that, though:
A=reshape( cat(4,cellArray{:}) ,3,6,6,[]);
result = sum(A,4);