
what is the best way to plot dates?
5 views (last 30 days)
Show older comments
So I have some data that I want to plot, but the points are not evenly space and I am struggling to create a graph. For example, I have the dates as:
07/07/2015 07/07/2015 04/08/2015 04/08/2015 01/09/2015 01/09/2015 06/10/2015 06/10/2015 03/11/2015 01/12/2015 01/12/2015 29/12/2015 29/12/2015 26/01/2016 26/01/2016 23/02/2016 23/02/2016 23/02/2016 08/03/2016 08/03/2016 22/03/2016 22/03/2016
and the corresponding values as:
91 5.91347086 57 7.962256484 47 6.8169175 72 7.696871529 53 9.854200762 63 1.16972852 61 3.669585297 63 9.22168862 52 9.237301232 56 2.713270456 114 5.395889039
What is the best way to create a graph out of this?
0 Comments
Answers (1)
Peter Perkins
on 13 Feb 2018
It would be good to post data that people can simply cut and paste.
You have 11 pairs of repeated dates, and what appears to be two data series. I guess you want to plot both series? In any recent version, MATLAB just plots dates. Nothing special. For example:
d = {'07/07/2015';'07/07/2015';'04/08/2015';'04/08/2015';'01/09/2015';'01/09/2015';'06/10/2015';'06/10/2015';'03/11/2015';'01/12/2015';'01/12/2015';'29/12/2015';'29/12/2015';'26/01/2016';'26/01/2016';'23/02/2016';'23/02/2016';'23/02/2016';'08/03/2016';'08/03/2016';'22/03/2016';'22/03/2016'};
xy = [91;5.91347086;57;7.962256484;47;6.8169175;72;7.696871529;53;9.854200762;63;1.16972852;61;3.669585297;63;9.22168862;52;9.237301232;56;2.713270456;114;5.395889039];
x = xy(1:2:end);
y = xy(2:2:end);
d = datetime(d(1:2:end));
plot(d,x,'b',d,y,'r')

3 Comments
Peter Perkins
on 13 Feb 2018
It's your data, so you probably know, but it does seem like you have two series. In any case, you can still create a datetime vector, and use plot.
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!