Skip certain times in datetime plot

조회 수: 8 (최근 30일)
Hamad
Hamad 2015년 2월 5일
댓글: Walter Roberson 2018년 9월 12일
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

답변 (1개)

Michelle Hirsch
Michelle Hirsch 2015년 2월 6일
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
Sagar
Sagar 2018년 9월 12일
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 2018년 9월 12일
However, this might not be compatible with datetime plots -- or at least it probably is not compatible with the automatic label changes upon zooming.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by