Azzera filtri
Azzera filtri

Summation of n-th columns of multiple matrix.

1 visualizzazione (ultimi 30 giorni)
I try to summate the 4th colums of this 15 matrices. I use following code:
P{1}=[0 18 0 0];
P{2}=[31 20 0 0];
P{3}=[51 25 0 0];
P{4}=[75 23.9 0 0];
P{5}=[76.2 25 0 1000];
P{6}=[84.7 25 0 1000];
P{7}=[93.2 31 0 1000];
P{8}=[109.2 46.7 0 1000];
P{9}=[127.2 49.7 0 1000];
P{10}=[145.2 31 0 1000];
P{11}=[161.2 25 0 0];
P{12}=[169.7 25 0 0];
P{13}=[178.2 23.9 0 0];
P{14}=[179.2 25 0 0];
P{15}=[188.4 25 0 0];
for k = 1 : 15
A{k} = P{k}(4)
y=sum(A{k})
end
Instead of y=6000 matlab show me that y=0. Maybe anyone show me my mistake.

Risposta accettata

Bhuvnesh Singh
Bhuvnesh Singh il 26 Feb 2018
To achieve this you can do something like :
y = 0
for k = 1 : 15
A{k} = P{k}(4)
y = y + A{k}
end

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by