MATLAB: How can I do this mathmatical operation

sum and subtraction column value

I wish to do sum and subtract in column 2 of 84×7 matrices between different rows of the element on the same column and produce the answers into an array. example @Column 3, a = [ 1 3 3 3 ; 2 2 2 2 ; 3 4 4 4 ; 4 0 1 0 ; 5 5 5 5 ; 1 1 1 1 ; 7 7 7 7 ] desired outcome: => b = [ 3 7 10 ]

Best Answer

I guess what you want is
for i=1:2:(length(a(:,3))-2)
b(i)= a(i,3)-a(i+1,3)+(a(i+2,3)-a(i+1,3))
end
b(2:2:end)=[];
Why length(a(:,3)-2)? It is to avoid exceed the dimension.