Convert date and time to seconds

32 次查看(过去 30 天)
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

采纳的回答

the cyclist
the cyclist 2014-5-26
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by