Skip certain times in datetime plot
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
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
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 Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!