How to set datetick at 10 minute intervals when data starts at random times
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pw
am 15 Apr. 2014
Kommentiert: Walter Roberson
am 12 Jun. 2016
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
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 15 Apr. 2014
tickstart = floor(start * 24 * 60 / 10) / (24 * 60 / 10);
now you can use tickstart:tenmin:last
1 Kommentar
Weitere Antworten (1)
Kelly Kearney
am 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 Kommentare
Trung Hieu Le
am 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
am 12 Jun. 2016
Kelly moved the repository; you can find it at https://github.com/kakearney/datelist-pkg
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!