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
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!