How to set datetick at 10 minute intervals when data starts at random times

조회 수: 3 (최근 30일)
I have several data sets that start at random times (e.g., 10:04:23, 08:27:59, etc). The time is in the serial date format which I use datetick to change to the mm/dd/yy HH:MM format . I am plotting experimental data versus time via a function. I want to plot the data every 10 minutes but I want the intervals to be multiples of 10. For example, if my data starts on Aug 1, 2013 10:04:23 I want my first tick mark to read 8/01/13 10:00 and show every 10 minutes until the end of the data. Because each data set starts at a different time I cannot just write a simple time subtraction function that would apply to all.
I am wondering if there is a way to get the time axis to plot every 10 minutes on a multiple of 10 minute using a loop or if/else statement. I do not want to have to go in and manually change the start tick each time.
Within my function I have the following where tenmin is 10 minutes as a serial date, start is the first time of the data and last is the end time of the data:
tenmin = 0.006944444496185;
set(gca,'XTick',[start:tenmin:last])
Thank you for any insight and help. -P. Wallace

채택된 답변

Walter Roberson
Walter Roberson 2014년 4월 15일
tickstart = floor(start * 24 * 60 / 10) / (24 * 60 / 10);
now you can use tickstart:tenmin:last

추가 답변 (1개)

Kelly Kearney
Kelly Kearney 2014년 4월 15일
I wrote this a little function ( datelist.m ) for exactly this purpose (although in my case, I usually want to label all months, where datetick tends to opt for annoying quarterly ticks by default). Works for any time interval...
start = datenum('01-Aug-2013 10:04:23');
last = datenum('01-Aug-2013 12:00:00');
t = linspace(start,last,100);
y = rand(size(t));
plot(t,y)
tk = datelist(start, last, 1:12, 1:31,1:24,0:10:60);
set(gca, 'xlim', [start last], 'xtick', tk)
datetick('keepticks', 'keeplimits')
  댓글 수: 3
Trung Hieu Le
Trung Hieu Le 2016년 6월 11일
Hi Sirs,
Do you keep the file (datelist.m) which I expect to follow for my case? Because I cannot get some points in your help. Thanks
Walter Roberson
Walter Roberson 2016년 6월 12일
Kelly moved the repository; you can find it at https://github.com/kakearney/datelist-pkg

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by