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

21 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 15 Apr 2014
tickstart = floor(start * 24 * 60 / 10) / (24 * 60 / 10);
now you can use tickstart:tenmin:last

More Answers (1)

Kelly Kearney
Kelly Kearney on 15 Apr 2014
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 Comments
Trung Hieu Le
Trung Hieu Le on 11 Jun 2016
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 on 12 Jun 2016
Kelly moved the repository; you can find it at https://github.com/kakearney/datelist-pkg

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!