Summation of n-th columns of multiple matrix.

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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by