Filter löschen
Filter löschen

How can I add many matrices?

1 Ansicht (letzte 30 Tage)
Adrian
Adrian am 22 Apr. 2014
Kommentiert: Adrian am 22 Apr. 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 Kommentare
Jan
Jan am 22 Apr. 2014
What exactly is "M(1)"? Is this a cell?
Adrian
Adrian am 22 Apr. 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!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 22 Apr. 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);

Kategorien

Mehr zu Multidimensional Arrays 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