summing element is a cell

2 Ansichten (letzte 30 Tage)
Esegboria Osarhemen
Esegboria Osarhemen am 5 Mär. 2019
Kommentiert: Jos (10584) am 8 Mär. 2019
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 Kommentar
Jos (10584)
Jos (10584) am 8 Mär. 2019
"without a loop". Why?
Loops are efficient and easy and sometime the best option :-)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 5 Mär. 2019
sum(cat(3,c{:}),3)
  2 Kommentare
Esegboria Osarhemen
Esegboria Osarhemen am 5 Mär. 2019
Bearbeitet: Esegboria Osarhemen am 5 Mär. 2019
I get this error
Error using cat
Dimension for sparse matrix concatenation must be <= 2.
Stephen23
Stephen23 am 6 Mär. 2019
Bearbeitet: Stephen23 am 8 Mär. 2019
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by