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 Exchange에서 Creating 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