Convert date and time to seconds

조회 수: 9 (최근 30일)
Ole
Ole 2014년 5월 26일
답변: the cyclist 2014년 5월 26일
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