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

请先登录,再进行评论。

类别

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