Effacer les filtres
Effacer les filtres

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 vue (au cours des 30 derniers jours)
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 commentaires
dpb
dpb le 3 Déc 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?
Joshua Firmin
Joshua Firmin le 3 Déc 2018
The Date isn't important in itself. I need it to graph in the correct order alongside other data

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 3 Déc 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 commentaires
dpb
dpb le 3 Déc 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by