Question

In Matlab, I have data in the following form:

  • "z", a 17'256x1 double, containing the residuals of a regression, e.g. -0.0596
  • "dates", a 17'256x1 cell, containing date- and timestamps of each observation in the regression (and therefore, of the residuals), e.g. '10/3/2011 9:30:00 PM'

What I would like to do: Plot the residuals versus the datestamp as label. The observations are not from a continuous sequence of days (i.e. there might be some gaps with no observations between days), and some days have more observations than others. I cannot have one label per observation because that would be too many labels. So I need to group them somehow, either by day or by month. That is, only show the month and day (e.g. 10/3) under all the observations from that day, or only show the month (e.g. 3) under all the observations from that month. How can I do that, using the data I have?

Était-ce utile?

La solution

You should be able to plot this without 'grouping' things. If you convert your dates to timestamps:

timestamps = cellfun(@(date)datenum(date), dates);

then you can do a normal plot:

plot(timestamps, z);

and Matlab will deal with the xaxis labels itself (i.e. it will spread them evenly over the time range of dates), but they will be the timestamp numbers. To get formatted dates on the xaxis, use:

datetick('x');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top