Plotting of dates error
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Daniel Shub
le 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 commentaires
Daniel Shub
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!