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

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