Adding matrices
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Brett Shoelson
2011년 2월 9일
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?
채택된 답변
Mahmoud Hammoud
2011년 2월 9일
a = rand(2,2,2); asum = sum(a,3);
asum is the sum along the 3rd dimension.
댓글 수: 0
추가 답변 (1개)
Fangjun Jiang
2011년 2월 9일
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()
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!