# How to plot time data at different/random time intervals?

10 views (last 30 days)
Juan Herrera on 5 Jul 2021
Commented: dpb on 29 Jul 2021
Like the title says I'd like to plot some vehicle data, which occurs every 5s, with timestamps of different non consecutive dates (different days). The problem that I have,is that there's a kind of a "gap" in the plot. I'm guessing because when the day changes there's a sustantial increment in the data in time (left picture). I'd like to have a similar outcome as in excel (right picture).
I appreciate your help.
MATLAB PLOT: EXCEL PLOT:
A1time:
'16-Oct-2019 09:22:05'
'16-Oct-2019 09:22:10'
'16-Oct-2019 09:22:15'
'16-Oct-2019 09:22:20'
'16-Oct-2019 09:22:25'
'22-Oct-2019 08:41:45'
'22-Oct-2019 08:41:50'
'22-Oct-2019 08:41:55'
'22-Oct-2019 08:42:00'
'22-Oct-2019 08:42:05'
A1qVeh:
318.819
358.549
480.068
692.451
417.788
351.383
0
232.397
1114.91
1520.94
so far I've tried plotting directly the datetime variable and used datenum & datetick.
figure()
plot (A1time,A1qVeh)
B1DateTime = A1time-datenum('16-Oct-2019','dd-mmm-yy')
figure()
plot(B1DateTime,A1qVeh)
dateFormat = 'HH:MM:SS';
datetick('x',dateFormat)
##### 2 CommentsShowHide 1 older comment
Juan Herrera on 6 Jul 2021
That's a great advice to attach the .mat file, will do next time.

dpb on 5 Jul 2021
While not sophisticated to handle general case to isolate the day start locations, the general idea is
A1time=datetime(A1time);
hL=plot(A1qVeh);
xticklabels(string(A1time))
hAx=gca;
hAx.XAxis.TickLabelRotation=90;
hAx.XAxis.FontSize=8;
leaves one with
dpb on 29 Jul 2021
I've wished for (and put in enhancement requests as long as 25-30 years ago) to allow "broken" axes to accomodate gaps when wanted/needed...

R2020a

### Community Treasure Hunt

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

Start Hunting!