Skip certain times in datetime plot
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hamad am 5 Feb. 2015
Kommentiert: Walter Roberson am 12 Sep. 2018
I am trying to plot timeseries data using the MATLAB R2014b "datetime" method to enable nice features such as auto-zooming in to timestamps, etc. The following is an example:
'21/01/2015 09:00:00' '1'
'21/01/2015 10:00:00' '2'
'21/01/2015 11:00:00' '3'
'21/01/2015 12:00:00' '4'
'22/01/2015 09:00:00' '5'
'22/01/2015 10:00:00' '6'
'22/01/2015 11:00:00' '7'
'22/01/2015 12:00:00' '8'
So I would use "datetime" on the first column, and plot it against the second column. The problem is, the data on Jan 21 is from 9am - 12pm, the next data point is on Jan 22 at 9am, but "datetime" will fill a large portion of the central part of the graph will interpolated values between data '4' and '5'. Is there a way to avoid this, so that I can still use datetime but restrict the plot to specific periods of interest?
Michelle Hirsch am 6 Feb. 2015
If you want to plot all of the data, but to not connect the line between some values, you could inject a NaN in your data where you want the line to break.
Here's an example of how to do it with brute force:
% Create your data
t = [datetime(2015,1,21,[9:12],0,0) datetime(2015,1,22,[9:12],0,0)]
d = 1:8;
% Inject the NaN into d. and put something into t. Doesn't matter what,
% since it won't plot.
d = [d(1:4) NaN d(5:end)];
t = [t(1:4) t(end) t(5:end)];
% Plot it
Walter Roberson am 12 Sep. 2018
However, this might not be compatible with datetime plots -- or at least it probably is not compatible with the automatic label changes upon zooming.
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!