필터 지우기
필터 지우기

adding a sequence of matrices

조회 수: 1 (최근 30일)
Rabeya
Rabeya 2012년 5월 19일
How can I add G number of matrices? I mean I need to sum G number of matrices. For example: G=3, so, x1=[1 2 3 4; 2 3 4 5], x2=[1 1 2 2; 2 3 3 4], x3=[4 5 6 7; 1 2 3 4].
I need x1+x2+x3
It seems very simple, but if G varies, say, in every run of a simulation, I need something general, like x1+x2+.....+xG
  댓글 수: 1
Andrei Bobrov
Andrei Bobrov 2012년 5월 19일
A simple example in numerical form

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

채택된 답변

the cyclist
the cyclist 2012년 5월 19일
One way:
Use cell arrays to define your individual arrays.
x{1}=[1 2 3 4; 2 3 4 5];
x{2}=[1 1 2 2; 2 3 3 4];
x{3}=[4 5 6 7; 1 2 3 4].
% ...
x{G} = [1 2 1 2; 8 8 8 8];
Then sum them with a loop
Y = x{1};
for gi = 1:G
Y = Y + x{gi};
end
  댓글 수: 1
Andrei Bobrov
Andrei Bobrov 2012년 5월 19일
sum(cat(3,x{:}),3)

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by