Plotting of dates error
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Daniel Shub
2011년 10월 17일
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
Daniel Shub
2011년 10월 17일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!