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 日

0 投票

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

2 件のコメント

Esegboria Osarhemen
Esegboria Osarhemen 2019 年 3 月 5 日
編集済み: 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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2019 年 3 月 5 日

コメント済み:

2019 年 3 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by