Effacer les filtres
Effacer les filtres

How can I add many matrices?

1 vue (au cours des 30 derniers jours)
Adrian
Adrian le 22 Avr 2014
Commenté : Adrian le 22 Avr 2014
For example, I have 1000 matrices, each of 500x120 in size: M(1), M(2), ..., M(1000)
I want to add in order to obtain a final matrix also of 500x120 in size: A = M(1) + M(2) + ... + M(1000) where A = [500x120]
I tried in many ways, but I couldn't do it. Could someone please give a hand? Thank you!
  2 commentaires
Jan
Jan le 22 Avr 2014
What exactly is "M(1)"? Is this a cell?
Adrian
Adrian le 22 Avr 2014
M(1) is the first 500x120 matrix from all 1000 matrices. I just want to be able to add many matrices. Instead of M(1), M(2),...M(1000), you can consider: a, b,...,n where n = 1000
So I want: A = a + b + ... + n where n = 1000
Thanks again!

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 22 Avr 2014
If the matrices are stored in a cell, convert it to a 3D array at first:
M{1} = rand(500, 120);
M{2} = rand(500, 120);
M{3} = rand(500, 120);
... etc
MM = cat(3, M{:});
Or if you have such a 3D array MM(500, 120, n) already:
Result = sum(MM, 3);

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by