Effacer les filtres
Effacer les filtres

date time convert to elapsed time

23 vues (au cours des 30 derniers jours)
David C
David C le 25 Avr 2012
I have a vector of date times in 'HH:MM:SS' format which I want to convert to elapsed time. Each cell is a 1 minute increment from the previous.
Right now I'm doing a for loop that loops the size of the entire vector, and does x(i)-x(1) to calculate the elapsed time (in minutes).
This seems kind of cumbersome code, and I feel like there's an easier way. Any recommendations?

Réponse acceptée

Thomas
Thomas le 25 Avr 2012
your cell array
c={'12:00:00' '12:00:01' '12:00:02' '12:00:03'}
d=datenum(c,'HH:MM:SS')
out=d-d(1);
time_sec=out*86400
  1 commentaire
David C
David C le 25 Avr 2012
super! Thanks guys!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 25 Avr 2012
datenum() the cell array of date strings to get out a vector of serial date numbers. Subtract the first value from the array to get the elapsed times in days. Multiply by 24*60 to get elapsed times in minutes. No loop should be needed.
  1 commentaire
Jamiat Nanteza
Jamiat Nanteza le 2 Nov 2023
Thank you. You saved me

Connectez-vous pour commenter.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by