Convert date and time to seconds

11 vues (au cours des 30 derniers jours)
Ole
Ole le 26 Mai 2014
Hi
I've measured a process as a function of time, and when I open the logging file (.txt) in MATLAB the date and time is saved in a char array. The measured variables are stored in an ordinary array. I have two columns (2 and 3) in the character array which contains date (dd.mm.yy) and time (HH:MM:SS). In total I have approximately 9000 rows of data. I would like to convert the date and time to seconds elapsed from first measured value. The first date and time registered would consequently be converted to approximately 0 seconds, the next would be 0seconds + x and so on.
date_string = strcat(textdata(2:end,2), {' '},textdata(2:end,3));
dateandtime = datenum(date_string, 'dd.mm.yyyy HH:MM:SS');
And then I'm stuck. I've been looking at etime, but it essentially only calculates the difference between two date vectors?
Thanks

Réponse acceptée

the cyclist
the cyclist le 26 Mai 2014
If I understand correctly, your variable dateandtime is going to be a vector of about 9000 date-times. The rest is simple:
dateandtime = (dateandtime-dateandtime(1)) * (24 * 60 * 60);

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time 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