Effacer les filtres
Effacer les filtres

adding a sequence of matrices

1 vue (au cours des 30 derniers jours)
Rabeya
Rabeya le 19 Mai 2012
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 commentaire
Andrei Bobrov
Andrei Bobrov le 19 Mai 2012
A simple example in numerical form

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 19 Mai 2012
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 commentaire
Andrei Bobrov
Andrei Bobrov le 19 Mai 2012
sum(cat(3,x{:}),3)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by