Create elapsed time vector for loop
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Evelyn Maniaki
am 17 Mär. 2021
Kommentiert: Evelyn Maniaki
am 19 Mär. 2021
Hi everyone!
I'm new to this so any help would be greatly appreciated!
I would like to analyse some accelerometer data and I'd like to convert the timestamp to elapsed time, with the start of recording being 0. Then, I'd like to create a for loop to do this for the entire column (a few thousand rows), and write the result in a new column.
(Some additional context, if helpful: I have already converted the datetime from 'yyyy-MM-dd HH:mm:ss.SSS' to 'HH:mm:ss.SSS' since the experiments are short and don't take more than a few minutes each. The sampling frequency is 100Hz and so I have samples every 0.001-0.002 seconds. I will then need to find peaks within different elapsed periods).
Could you please help me with the conversion and for loop creation? I have foundhttps://uk.mathworks.com/matlabcentral/answers/386394-plot-datetime-vector-as-elapsed-time-in-seconds-from-start-of-meaurement, https://uk.mathworks.com/matlabcentral/answers/373223-how-to-calculate-time-elapsed-time-in-gmt-format and https://uk.mathworks.com/matlabcentral/answers/410089-create-a-function-to-find-elapsed-time-with-string-of-date-and-times-through-samples but I am not sure how to repurpose them.
Thank you in advance!
Evelyn
0 Kommentare
Akzeptierte Antwort
Seth Furman
am 18 Mär. 2021
Bearbeitet: Seth Furman
am 18 Mär. 2021
1) You can convert timestamp data into elapsed time using datetime subtraction.
>> dt = datetime(2020,1,1:5)
dt =
1×5 datetime array
01-Jan-2020 02-Jan-2020 03-Jan-2020 04-Jan-2020 05-Jan-2020
>> dt - dt(1)
ans =
1×5 duration array
00:00:00 24:00:00 48:00:00 72:00:00 96:00:00
2) MATLAB supports vectorized operations so you can directly subtract a scalar or vector datetime from a vector datetime as in the example above.
3) See the following link for how to add new variables to a table.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!