# Show time in x axis with increments of 10minutes

12 views (last 30 days)
Mathan on 4 Apr 2022
Commented: Mathan on 5 Apr 2022
Hello,
I was wondering whether it is possible to plot a graph with time on x axis that varies with 10 minute (or 15 minute or 20 minute) increment (i.e. as per our choice). For instance, I have two times:
t_start = 10-Jun-2015 03:30:00 (which is the start time)
t_end = 10-Jun-2015 05:00:00 (is the end time)
How can I have a plot with x axis containing ticks such as 03:30, 03:40, 03:50........04:40, 04:50, 05:00.
I tried:
xtks = linspace(t_start, t_end, 20);
xticks(xtks);
xlim([t_start, t_end]);
datetick('x','HH:MM','keepticks', 'keeplimits');
But this just produces an x axis with 20 equally divided ticks (not increments as shown above). I tried with 10, 15, etc instead of 20 for xtks but still it does'not come out as expected.
Any help is appreciated.
Thanks
##### 2 CommentsShowHide 1 older comment
Mathan on 4 Apr 2022
Both of them simply look like this (has this exact format and not decimal format):
t_start = '10-Jun-2015 03:30:00'
t_end = '10-Jun-2015 05:00:00'

Walter Roberson on 4 Apr 2022
t_start = datetime('10-Jun-2015 03:30:00'); %(which is the start time)
t_end = datetime('10-Jun-2015 05:00:00'); %(is the end time)
t = t_start : minutes(1) : t_end;
ndata = length(t);
data = rand(1, ndata);
plot(t, data);
xticks(t_start:minutes(15):t_end); Mathan on 5 Apr 2022
Thank you again.