How do I get the value of seconds in a datetime table?

조회 수: 10 (최근 30일)
Hessa Lootah
Hessa Lootah 2020년 12월 3일
편집: Cris LaPierre 2020년 12월 3일
I collected some acceleration values using the matlab application, however i don't know how to convert the timestamps to seconds elapased.
  댓글 수: 2
dpb
dpb 2020년 12월 3일
'Pends. Are the timestamps real time or some other measure?
If real time, then just subtract the first value from the data.
Hessa Lootah
Hessa Lootah 2020년 12월 3일
the timestamps from the sensor came out with the date(dd:mm:yy), time in hours, min, second and millisecond.
so basically subtract the first value from the last value and figure out how long that took?

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 12월 3일
편집: Cris LaPierre 2020년 12월 3일
+1 to dpb's comment. Subtracting datetimes gives you a duration. You can convert your duration to your desired units - days, hours, minutes, seconds, etc by setting the duration format. See more here.
Some code taken from this example.
% Create a vetor of times
t = datetime('now') + minutes(1:0.25:3)
t = 1×9 datetime array
03-Dec-2020 23:09:58 03-Dec-2020 23:10:13 03-Dec-2020 23:10:28 03-Dec-2020 23:10:43 03-Dec-2020 23:10:58 03-Dec-2020 23:11:13 03-Dec-2020 23:11:28 03-Dec-2020 23:11:43 03-Dec-2020 23:11:58
% compute elapsed time
dt = t - t(1)
dt = 1×9 duration array
00:00:00 00:00:15 00:00:30 00:00:45 00:01:00 00:01:15 00:01:30 00:01:45 00:02:00
% convert elapsed time to seconds
dt.Format = 's'
dt = 1×9 duration array
0 sec 15 sec 30 sec 45 sec 60 sec 75 sec 90 sec 105 sec 120 sec

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by