Clear Filters
Clear Filters

How to add the contents of all cells in a row of a cell array together

2 views (last 30 days)
Hi,
I've created a cell array that has 1 row. In each element of the cell array is a 3D matrix. I want to add all the matrices in the row of the cell array together. How do I do that?

Accepted Answer

Star Strider
Star Strider on 27 Jul 2016
The plus function only takes two arguments, so using it with arrayfun failed. A loop is apparently the only option, producing the summed matrix ‘S’:
C = {randi(9, 3, 3, 3), randi(9, 3, 3, 3), randi(9, 3, 3, 3), randi(9, 3, 3, 3)};
S = 0;
for k1 = 1:size(C,2)
S = S + C{k1};
end
This of course assumes all the matrices are the same size, as they are here.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!