Effacer les filtres
Effacer les filtres

Finding the delta (subtraction) of two cells in an existing matrix

18 vues (au cours des 30 derniers jours)
itzhak mal
itzhak mal le 16 Avr 2019
Commenté : Star Strider le 16 Avr 2019
Hi,
I have a matrix with 10^7 rows and 17 columns.
Column number 17 is the time and I want to add another column, 18, that will have the delta of these time steps..
for example:
1
5
15
will yield
4
10
I get do loops cause there are 10^7 million rows.. it would take ages. Any ideas? Perhaps a boolian expression would do the trick? Thanks!!!

Réponse acceptée

Star Strider
Star Strider le 16 Avr 2019
Use the diff (link) function, and add a ‘0’ to the output, so the row lengths will be the same:
time = [ 1
5
15]
dtime = [0; diff(time)]
producing:
time =
1
5
15
dtime =
0
4
10
  2 commentaires
itzhak mal
itzhak mal le 16 Avr 2019
thank you!
Star Strider
Star Strider le 16 Avr 2019
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by