summing element is a cell

1 次查看(过去 30 天)
Esegboria Osarhemen
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 个评论
Jos (10584)
Jos (10584) 2019-3-8
"without a loop". Why?
Loops are efficient and easy and sometime the best option :-)

请先登录,再进行评论。

回答(1 个)

Stephen23
Stephen23 2019-3-5
sum(cat(3,c{:}),3)
  2 个评论
Esegboria Osarhemen
编辑:Esegboria Osarhemen 2019-3-5
I get this error
Error using cat
Dimension for sparse matrix concatenation must be <= 2.
Stephen23
Stephen23 2019-3-6
编辑:Stephen23 2019-3-8
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by