how can I do this mathmatical operation?
이전 댓글 표시
I wish to do sum and subtract in column 2 of 84x7 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 ]
댓글 수: 5
madhan ravi
2018년 10월 22일
편집: madhan ravi
2018년 10월 22일
b = [ 3 7 10 ] is not clear
Rik
2018년 10월 22일
Could you show more of the calculation steps? The calculation is not clear to me. The sum of the columns is [23 22 23 22], so I don't see how any subtraction would result in your output.
Kevin Chng
2018년 10월 22일
편집: Kevin Chng
2018년 10월 22일
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.
Young Lee
2018년 10월 23일
채택된 답변
추가 답변 (1개)
This works without a loop:
n = size(a, 1);
b = a(1:2:n-2, 3) - 2 * a(2:2:n-1, 3) + a(3:2:n, 3)
카테고리
도움말 센터 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!