what is the best way to plot dates?

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?

Answers (1)

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

Sorry I am new to Matlab and have just kind of been thrown into the deep end so I am trying to learn a lot in a short amount of time. The repeated dates just represent multiple data values taken on the same day, so I would like to plot it all as one series.
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.
Well I want to plot it as one series, so I am trying to use
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];
plot(d,xy)
But it doesn't work. Tells me invalid first data argument

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!