필터 지우기
필터 지우기

how can i subtract the elements in a coloumn ?

조회 수: 2 (최근 30일)
farfar
farfar 2017년 10월 13일
편집: Jan 2017년 10월 13일
hello
for example, I have : a=[380 0;381 1;382 2;383 3;383 4;383 5;384 6]
I want to go into first column and do this : (381-380), (382-381), (383-382),
how can i do this in a loop or other ways? Thanks for i=1:length(a) b=a(i,1) ????? end

채택된 답변

John D'Errico
John D'Errico 2017년 10월 13일
Start reading the tutorials.
diff(a(:,1))

추가 답변 (1개)

Jan
Jan 2017년 10월 13일
편집: Jan 2017년 10월 13일
Do you mean:
diff(a(:,1))
Alternatively with a loop:
n = size(a, 1) - 1;
b = zeros(1, n);
for k = 1:n
b(k) = a(k+1, 1) - a(k, 1);
end
Or without a loop:
b = a(2:end) - a(1:end - 1);

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by