Plotting of dates error
1 view (last 30 days)
Show older comments
Dear all, Should be an easy question but I'm having much difficuly plotting non-monotically increasing dates with my data. Heres a simplified version of my code:
x= ['20 Sep 2011'
'21 Sep 2011'
'21 Sep 2011'
'23 Sep 2011'
'27 Sep 2011'
'28 Sep 2011'
'29 Sep 2011'
'1 Oct 2011'];
y = [ 30255600 30248900 30252600 30281600 30223900 30229100 30336700 30270800 ];
dates = datenum(x, 'dd mmm yyyy'); plot(dates, y, '.-y')
labels = datestr(dates, 20); set(gca, 'XTick', dates); set(gca, 'XTickLabel', labels);
I get an error: ??? Error using ==> set Values must be monotonically increasing
Error in ==> ecf_read at 127 set(gca, 'XTick', dates);
Can anyone help?
Regards, Jim
0 Comments
Accepted Answer
Daniel Shub
on 17 Oct 2011
While there seems to be at least two bugs ...
The data 21 Sep 2011 is listed twice. The error probably should be "Values must be STRICTLY monotonically increasing." You need to do something to get rid of the identical dates in the XTick call. You could do something like unique.
doc unique
The second problem is that 1 Oct 2011 has less characters than the other dates. You cannot do concatenation like that. You need a cell array.
2 Comments
Daniel Shub
on 17 Oct 2011
Then post some minimal code that reproduces the error. Yes, a cell array will allow you to have dates with different numbers of characters. The problem still remains that something about dates is not monotonically increasing. I would suggest using unique and sort on dates after the plotting, but before the setting of the ticks and the labeling.
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!