Display correct time on x-axis
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
cosine92
am 24 Jan. 2018
Kommentiert: cosine92
am 24 Jan. 2018
Hello! I am trying to plot time on the x-axis and I am having some difficulty. The times I have are in a text file and look like this:
9:36:36 PM
9:38:10 PM
9:39:44 PM
9:41:18 PM
9:42:54 PM
...
1:35:22 AM
1:36:56 AM
1:38:32 AM
1:40:06 AM
1:41:42 AM
1:43:16 AM
I have tried importing the text file as a column vector using the datetime format. When I do so, I see all the correct times. However, when I go to plot them on the x-axis the displayed times do not correspond to my times, and I also get the date at the end which I do not want. I've included an image to show what I mean.
I should add that I'm fairly new to matlab, so I'm still learning the ropes!
Thank you very much!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 24 Jan. 2018
Bearbeitet: Walter Roberson
am 24 Jan. 2018
The graph is arguably correct. Your times have no date attached, so the 1:35:22 AM is on the same day as the 9:36:36 PM that happened to be listed earlier.
What you can do is import them as datetime objects, and then:
mask = times < times(1); %find ones that wrapped to the next day
times(mask) = times(mask) + 1; %move them to the next day.
This assumes that the data does not cover more than 24 hours.
To get rid of the date on the axes, set the Format property of the datetime objects before you plot()
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Printing and Saving 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!