converting a column of text dates and time to actual day fraction

6 views (last 30 days)
How can I convert a column of text that is in the form of 'yyyy-MM-ddTHH:mm:ss.SSSZ' (expample: 2021-03-05T19:09:32.840Z) to something I can use as an X-axis on a plot. I'm kind of new at this. I'm really more concerned with the tiime of day rather than the year.
Thanks,
Shane

Answers (1)

Cris LaPierre
Cris LaPierre on 24 Mar 2021
Convert it to a datetime, and use that as your x value.
T = "2021-03-05T19:09:32.840Z";
x = datetime(T,"InputFormat",'yyyy-MM-dd''T''HH:mm:ss.SSS''Z')
x = datetime
05-Mar-2021 19:09:32
plot(x,5,'*g')
  2 Comments
Shane Luker
Shane Luker on 26 Mar 2021
Edited: Shane Luker on 26 Mar 2021
It didn't work exactly but you got me looking in the right area. The following was what I used to read the first column of the text data: text(:,1)
I converted the text to a DateString. The infmt was the format of that column of text. But the datetime functions is what I used. The time variable didn't show the fractional seconds by default. I had to use time.format. Thanks for your help though.
DateString = text(:,1);
infmt = 'yyyy-MM-dd''T''HH:mm:ss.SSS''Z';
time = datetime(DateString,"InputFormat",infmt);
time(1,:) = [];
time.Format = 'HH:mm:ss.SSS';
Cris LaPierre
Cris LaPierre on 26 Mar 2021
More lines of code than you need, but if it works for you, that's good enough for me.

Sign in to comment.

Categories

Find more on Word games in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!