Add duration object to datetime object to get new datetime object
2 次查看(过去 30 天)
显示 更早的评论
I'm reading a text file that looks like this:
2024-05-11 00:34:35 1.2 sta/lta 2.0 8.0 3.5 2.5 max 363.3 rms 127.2 id: L MSS1
2024-05-11 01:19:32 2.2 sta/lta 2.0 8.0 3.5 2.5 max 1126.7 rms 328.4 id: t MSS1
2024-05-11 01:30:10 1.7 sta/lta 2.0 8.0 3.5 2.5 max 597.3 rms 162.4 id: t MSS1
2024-05-11 04:52:52 2.7 sta/lta 2.0 8.0 3.5 2.5 max 2516.3 rms 657.6 id: t MSS1
2024-05-11 07:14:16 2.3 sta/lta 2.0 8.0 3.5 2.5 max 2644.7 rms 626.9 id: t MSS1
2024-05-11 09:45:07 1.9 sta/lta 2.0 8.0 3.5 2.5 max 1768.3 rms 558.0 id: u MSS1
2024-05-11 19:44:04 2.2 sta/lta 2.0 8.0 3.5 2.5 max 1027.7 rms 229.0 id: r MSS1
I use readtable, and it returns this:
>> A = readtable( fileTriggerIDs )
A =
7×15 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15
__________ ________ ____ ___________ ____ ____ ____ ____ _______ ______ _______ _____ _______ _____ ________
11/05/2024 00:34:35 1.2 {'sta/lta'} 2 8 3.5 2.5 {'max'} 363.3 {'rms'} 127.2 {'id:'} {'L'} {'MSS1'}
11/05/2024 01:19:32 2.2 {'sta/lta'} 2 8 3.5 2.5 {'max'} 1126.7 {'rms'} 328.4 {'id:'} {'t'} {'MSS1'}
11/05/2024 01:30:10 1.7 {'sta/lta'} 2 8 3.5 2.5 {'max'} 597.3 {'rms'} 162.4 {'id:'} {'t'} {'MSS1'}
11/05/2024 04:52:52 2.7 {'sta/lta'} 2 8 3.5 2.5 {'max'} 2516.3 {'rms'} 657.6 {'id:'} {'t'} {'MSS1'}
11/05/2024 07:14:16 2.3 {'sta/lta'} 2 8 3.5 2.5 {'max'} 2644.7 {'rms'} 626.9 {'id:'} {'t'} {'MSS1'}
11/05/2024 09:45:07 1.9 {'sta/lta'} 2 8 3.5 2.5 {'max'} 1768.3 {'rms'} 558 {'id:'} {'u'} {'MSS1'}
11/05/2024 19:44:04 2.2 {'sta/lta'} 2 8 3.5 2.5 {'max'} 1027.7 {'rms'} 229 {'id:'} {'r'} {'MSS1'}
A.Var1 is a datetime array and A.Var2 is a duration array.
How do I combine them to get one datetime array?
I tried adding them, but the results are nonsense:
>> A.Var1 + A.Var2
ans =
7×1 datetime array
2024-05-11 12:34:35
2024-05-11 01:19:32
2024-05-11 01:30:10
2024-05-11 04:52:52
2024-05-11 07:14:16
2024-05-11 09:45:07
2024-05-11 07:44:04
0 个评论
采纳的回答
Cris LaPierre
2024-5-14
The results seem correct if you consider the time is being displayed in 12-hr format instead of 24 hour format.
A = readtable('triggerIDs.txt')
DT = A.Var1 + A.Var2;
DT.Format = 'yyyy-MM-dd HH:mm:ss'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!