Effacer les filtres
Effacer les filtres

Calculate difference between successive vector values.

169 vues (au cours des 30 derniers jours)
William Summers
William Summers le 21 Août 2012
Commenté : Dav le 10 Août 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

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 21 Août 2012
Modifié(e) : Azzi Abdelmalek le 21 Août 2012
A=[1,2,3,3,0]
B=diff(A)
  5 commentaires
Voss
Voss le 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)
Dav
Dav le 10 Août 2023
Was looking for a function that did this, thanks!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by