adding a sequence of matrices

1 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by