Summing all the Matrices in a Cell Array?

Lets say i have a cell array with 3 7x2 matrices in it:
.
.
How do i sum them up so to get a single 7x2 matrix?
In this exmaple, i only have 3 matrices.
But i may have a cell array with maybe 100+ matrices.
How should i do it?

댓글 수: 1

Matt J
Matt J 2014년 11월 5일
편집: Matt J 2014년 11월 5일
You probably should not be in this situation to begin with. Whatever code you're using to create the cell array, should probably be organizing the data as a 7x2xP numeric array instead. Most operations on an MxNxP array will be more efficient than with the MxN slices split across P cells.
An exception to this is when M*N is large and you're trying to avoid the copies that MATLAB makes when you do things like
a=A(:,:,i)
but the slices would have to be very very large to warrant that.

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

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 5일
편집: Azzi Abdelmalek 2014년 11월 5일

4 개 추천

a={rand(7,2) rand(7,2) rand(7,2)} % This is an example
b=sum(cat(3,a{:}),3)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2014년 11월 5일

편집:

2014년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by