Adding matrices

14 Ansichten (letzte 30 Tage)
Michael Joslin
Michael Joslin am 9 Feb. 2011
I have an m by m by n set of matrices and I want to add all of the matrices in the n dimension so I would end up with only one m by m matrix. I have tried several different ways to do this but I just cannot come up with a set of code that does the addition for any number of n matrices.
  1 Kommentar
Brett Shoelson
Brett Shoelson am 9 Feb. 2011
What exactly do you mean by a set of matrices? Can you show the form of your data? Is this a cell array? Lots of separate variables?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mahmoud Hammoud
Mahmoud Hammoud am 9 Feb. 2011
a = rand(2,2,2); asum = sum(a,3);
asum is the sum along the 3rd dimension.

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 9 Feb. 2011
a=rand(2,3,4); b=sum(a,3)
b =
2.8451 2.1572 1.6369
1.9019 0.9626 2.0225
Is this what you want?
The trick is to read the help of sum()

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by