Calculate difference between successive vector values.
46 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
William Summers
am 21 Aug. 2012
Kommentiert: Dav
am 10 Aug. 2023
Hi all, Hopefully a straightforward question, but one that I'm struggling with. I have a vector and want to create a new vector whose values are equal to the difference between successive values from the previous vector. e.g A = [1,2,3,3,0] want B = [1,1,0,-3]
What is the simplest way of doing this? Many thanks in advance. Will
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 21 Aug. 2012
Bearbeitet: Azzi Abdelmalek
am 21 Aug. 2012
A=[1,2,3,3,0]
B=diff(A)
5 Kommentare
Voss
am 5 Jan. 2023
The method given in Jan's comment above uses the colon operator:
A = [1,2,3,3,0];
B = A(2:end) - A(1:end-1)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!