Display correct time on x-axis

조회 수: 8 (최근 30일)
cosine92
cosine92 2018년 1월 24일
댓글: cosine92 2018년 1월 24일
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!

채택된 답변

Walter Roberson
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()
  댓글 수: 1
cosine92
cosine92 2018년 1월 24일
Ah perfect! Thank you so much!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by