Skip certain times in datetime plot

7 visualizaciones (últimos 30 días)
Hamad
Hamad el 5 de Feb. de 2015
Comentada: Walter Roberson el 12 de Sept. de 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:
dataToPlot =
'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?
Thanks, Hamad

Respuestas (1)

Michelle Hirsch
Michelle Hirsch el 6 de Feb. de 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
plot(t,d)
  3 comentarios
Sagar
Sagar el 12 de Sept. de 2018
Dear Hamad, did you find a way to do this? I want to do exactly the same thing as you want.
Walter Roberson
Walter Roberson el 12 de Sept. de 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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by