Borrar filtros
Borrar filtros

Add duration object to datetime object to get new datetime object

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 14 de Mayo de 2024
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')
A = 7x15 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 __________ ________ ____ ___________ ____ ____ ____ ____ _______ ______ _______ _____ _______ _____ ________ 2024-05-11 00:34:35 1.2 {'sta/lta'} 2 8 3.5 2.5 {'max'} 363.3 {'rms'} 127.2 {'id:'} {'L'} {'MSS1'} 2024-05-11 01:19:32 2.2 {'sta/lta'} 2 8 3.5 2.5 {'max'} 1126.7 {'rms'} 328.4 {'id:'} {'t'} {'MSS1'} 2024-05-11 01:30:10 1.7 {'sta/lta'} 2 8 3.5 2.5 {'max'} 597.3 {'rms'} 162.4 {'id:'} {'t'} {'MSS1'} 2024-05-11 04:52:52 2.7 {'sta/lta'} 2 8 3.5 2.5 {'max'} 2516.3 {'rms'} 657.6 {'id:'} {'t'} {'MSS1'} 2024-05-11 07:14:16 2.3 {'sta/lta'} 2 8 3.5 2.5 {'max'} 2644.7 {'rms'} 626.9 {'id:'} {'t'} {'MSS1'} 2024-05-11 09:45:07 1.9 {'sta/lta'} 2 8 3.5 2.5 {'max'} 1768.3 {'rms'} 558 {'id:'} {'u'} {'MSS1'} 2024-05-11 19:44:04 2.2 {'sta/lta'} 2 8 3.5 2.5 {'max'} 1027.7 {'rms'} 229 {'id:'} {'r'} {'MSS1'}
DT = A.Var1 + A.Var2;
DT.Format = 'yyyy-MM-dd HH:mm:ss'
DT = 7x1 datetime array
2024-05-11 00: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 19:44:04

Más respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by