Applying time axis limits to plots in UTC time

조회 수: 25 (최근 30일)
Calum
Calum 2024년 3월 13일
댓글: Voss 2024년 3월 13일
Hi folks, I was wondering if someone could help with some trouble I am having with regards to the formatting of some graphs I have made.
After some time I have managed to get my graphs to output what I need, with the x-axis displaying in hh:mm:ss of the day (duration type) as I had hoped. I can still apply y-axis limits using the standard ylim function since these values are decimal. However, I am unable to use xlim for my time axis to clip my plots accordingly.
Using, for example, xlim([11:17:00 11:17:30]) returns an error stating that limits 'must be a 2-element vector of increasing durations'. When i convert these hh:mm:ss times back into seconds and try the xlim, I get the same error. Does anyone know how I might go about fixing this with time durations in this format?
Thanks.

채택된 답변

Voss
Voss 2024년 3월 13일
Here's an example of setting the axes x-limits using duration values:
x = duration(1,1:30,0) % duration x
x = 1×30 duration array
Columns 1 through 18 01:01:00 01:02:00 01:03:00 01:04:00 01:05:00 01:06:00 01:07:00 01:08:00 01:09:00 01:10:00 01:11:00 01:12:00 01:13:00 01:14:00 01:15:00 01:16:00 01:17:00 01:18:00 Columns 19 through 30 01:19:00 01:20:00 01:21:00 01:22:00 01:23:00 01:24:00 01:25:00 01:26:00 01:27:00 01:28:00 01:29:00 01:30:00
y = rand(size(x)); % random y
plot(x,y) % plot
xl = duration(1,[10 15],0) % duration x-lim values
xl = 1×2 duration array
01:10:00 01:15:00
xlim(xl) % apply the x-lim
  댓글 수: 2
Calum
Calum 2024년 3월 13일
Thanks Voss - creating array in the right format using the duration function is the kind of thing I was looking for!
Calum.
Voss
Voss 2024년 3월 13일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by