Hi All, I have several days worth of time stamped data. Unfortunatly the date has not been provided. How can I convert the time to datetime and increase the date by one day when the time passes 00:00:00? Thankyou
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Sample of Data at 'change of day'
23:59:57,0.0010465
23:59:58,0.0010821
23:59:59,0.0010785
00:00:00,0.0010473
00:00:02,0.0008437
00:00:03,0.0011811
2 Commenti
dpb
il 3 Dic 2018
Do you know the start date (from the file timestamp, maybe, or other means)?
Is time of day of significance or could you do just as well with a duration timeseries as long as it reflects proper sampling interval?
Risposta accettata
dpb
il 3 Dic 2018
tsd=readtable('tsd.txt');
tsd.Var1=datetime(tsd.Var1);
du=[duration(0,0,0);diff(tsd.Var1)];
ix=find(du<0);
tsd.Var1(ix:end)=tsd.Var1(ix:end)+1;
>> tsd =
6×2 table
Var1 Var2
____________________ _________
03-Dec-2018 23:59:57 0.0010465
03-Dec-2018 23:59:58 0.0010821
03-Dec-2018 23:59:59 0.0010785
04-Dec-2018 00:00:00 0.0010473
04-Dec-2018 00:00:02 0.0008437
04-Dec-2018 00:00:03 0.0011811
>>
Rinse and repeat...a loop or arrayfun over length of ix for the locations of negative values will be simplest to code methinks. One could also find the breaks between and add the successive number of days and build that vector of corrections.
2 Commenti
dpb
il 3 Dic 2018
As you note, datetime will default to current date lacking info; you can always specify a specific date if needs be to reflect the actual time of the acquisition.
Or, of course, if isn't important at all about time-of-day, then you can just subtract the first element and have simply zero-based duration instead.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!