Summation of n-th columns of multiple matrix.

1 view (last 30 days)
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.

Accepted Answer

Bhuvnesh Singh
Bhuvnesh Singh on 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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!