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

1 view (last 30 days)
I have a 6x6x645 cell array, call it cellArray. So for each element i, where , of cellArray(:,:,i) we have a 6x6 cell. Each of these 6x6 cells themselves have 1x3 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 1x3 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 6x6 cell containing 1x3 matrices with the sums of all the intervals. How do you sum over this?

Accepted Answer

Matt J
Matt J on 5 Jul 2019
Edited: Matt J on 5 Jul 2019
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);
  1 Comment
Jeroen
Jeroen on 5 Jul 2019
You are right, I should not have put the confidence intervals in one cell. The script had to run for 4,5 hours, so better to reshape now than to run again. Thank you!!

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!