필터 지우기
필터 지우기

How can I find the difference between adjacent elements while ignoring the first value?

조회 수: 3 (최근 30일)
I have the following column vector.
data = randperm(100,15)';
Is there a way of using the "diff" function to find the difference between adjacent elements while ignoring the first one? In other words, I would like the calculation to start with elements 2 and 3 then 4 and 5 etc.
Appreciate the help! Thanks.

채택된 답변

Stephen23
Stephen23 2021년 2월 15일
diff(data(2:end))
  댓글 수: 5
Stephen23
Stephen23 2021년 2월 15일
편집: Stephen23 2021년 2월 15일
Where vec is your vector of 14 elements:
out = vec(2:2:end)-vec(1:2:end)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by