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 comentario

Jos (10584)
Jos (10584) el 8 de Mzo. de 2019
"without a loop". Why?
Loops are efficient and easy and sometime the best option :-)

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 5 de Mzo. de 2019

0 votos

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

2 comentarios

Esegboria Osarhemen
Esegboria Osarhemen el 5 de Mzo. de 2019
Editada: Esegboria Osarhemen el 5 de Mzo. de 2019
I get this error
Error using cat
Dimension for sparse matrix concatenation must be <= 2.
Stephen23
Stephen23 el 6 de Mzo. de 2019
Editada: Stephen23 el 8 de Mzo. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Mzo. de 2019

Comentada:

el 8 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by