Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Stephen23
Stephen23 am 15 Feb. 2021
diff(data(2:end))
  5 Kommentare
Stephen23
Stephen23 am 15 Feb. 2021
Bearbeitet: Stephen23 am 15 Feb. 2021
Where vec is your vector of 14 elements:
out = vec(2:2:end)-vec(1:2:end)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by