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

2 次查看(过去 30 天)
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?

采纳的回答

Star Strider
Star Strider 2016-7-27
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by