dates missing in time series - how to remove discontinuity
4 views (last 30 days)
Show older comments
I am plotting some daily time series data and there are about 60 contiguous days missing from the middle of the data set. When i plot, I am getting this ugly discontinuity where there are missing days and I can't, for the life of me, figure out how to close this "gap." I'm using Matlab 2012b on Mac OS X. Thanks in advance.
my code:
figure
plot(dates,Y,'linewidth',1)
set(gca,'XTick',dates)
datetick('x','mm-yyyy')
xlabel('Date')
2 Comments
Iain
on 16 May 2013
I suspect dates has some NaN in it. If you:
t = isnan(dates); dates(t) = []; Y(t) = [];
Then you ought to get the plot without the gap.
It may make more sense to interpolate to get the missing dates (if you have valid Y data)
Accepted Answer
José-Luis
on 17 May 2013
What do you dates look like? If it is something like 800415 (ddmmyy) then there will be a gap at the end of every month and a larger one at the end of every year. If that is the case an idea is to use Matlab day number.
doc datenum
In the example above:
serial_date = datenum(800415,'ddmmyy');
The function works with arrays and for plenty of date formats. You could then
plot(serial_data,your_data);
2 Comments
More Answers (0)
See Also
Categories
Find more on Dates and Time 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!