summing element is a cell

I have a 1x50 cell 'c', where each element in the cell is a nxn matrix, how can I sum all 50 matrices (c{1}+c{2}+c{3}+.....c{50}) without a loop?

1 个评论

"without a loop". Why?
Loops are efficient and easy and sometime the best option :-)

请先登录,再进行评论。

回答(1 个)

Stephen23
Stephen23 2019-3-5

0 个投票

sum(cat(3,c{:}),3)

2 个评论

I get this error
Error using cat
Dimension for sparse matrix concatenation must be <= 2.
Either:
  1. convert the sparse matrices to full matrices and use the answer I gave you, or
  2. mess around with cat and reshape and permute and sum, or
  3. use a loop.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by