필터 지우기
필터 지우기

How can I add many matrices?

조회 수: 1 (최근 30일)
Adrian
Adrian 2014년 4월 22일
댓글: Adrian 2014년 4월 22일
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
Jan
Jan 2014년 4월 22일
What exactly is "M(1)"? Is this a cell?
Adrian
Adrian 2014년 4월 22일
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!

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2014년 4월 22일
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);

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by