Display correct time on x-axis
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2018-1-24
编辑:Walter Roberson
2018-1-24
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()
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!