How to plot duration where time rolls over days?

1 visualizzazione (ultimi 30 giorni)
Danielle
Danielle il 11 Ago 2020
Risposto: Star Strider il 11 Ago 2020
I have raw data that is in the format "dayofyear:hh:mm:ss" format. When I run a script that usually works for duration in a single day I have no issues, however, this data set started at 212:22:50:26.0000 and ends at 213:02:07:40.0000.
The plot will shoves the beginning time all the way to the right (like it would be at the end of the day) and the rest of the plot gets shoved to the left (as if it was the beginning of the day) but it's not taking into account the rollover in day of year.

Risposte (1)

Star Strider
Star Strider il 11 Ago 2020
You will need to convert these to your duration array, however the day-of-year conversion (using DDD in the InputFormat string) will do what you want.
Try this:
InpFmt = 'DDD:HH:mm:ss.SSSS';
OptFmt = 'yyyy-MM-dd HH:mm:ss.SSSS';
t1 = datetime('212:22:50:26.0000', 'InputFormat',InpFmt, 'Format',OptFmt)
t2 = datetime('213:02:07:40.0000', 'InputFormat',InpFmt, 'Format',OptFmt)
producing:
t1 =
datetime
2020-07-30 22:50:26.0000
t2 =
datetime
2020-07-31 02:07:40.0000
You may also need to adjust the year if it not the current year. That should be straightforward.
.

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by