hi,i have a problem to fix xticks in 2d plot.
i have a time series from 1990,01 up to 2020,03;when i plot my data ,the xaxis is full of date,how i could specify the date will be shown in x axis.
appreciate in advance

 채택된 답변

Rik
Rik 2020년 5월 15일

1 개 추천

datetick seems a good place to start. Otherwise you can see if the xtickformat function suits your need.

댓글 수: 3

masoumeh solgi
masoumeh solgi 2020년 5월 15일
y=gyields(:,1)
startDate = datenum('01-1990')
endDate = datenum('01-2019');
xData = linspace(startDate,endDate,360)
plot(xData,y);
ax = gca;
ax.XTick = xData;
datetick('x','yyyy')
these are my code,but i have this error
"Error using matlab.graphics.axis.decorator.DatetimeRuler/validateTicks
Value must be a vector of increasing datetime values.
Error in matlab.graphics.axis.decorator.DatetimeRuler/setTicksDelegate"
Rik
Rik 2020년 5월 15일
The datenum values that are generated by your code didn't match what I expected, so I edited it a bit. The code below runs without errors or warnings.
S=load('example.mat');y=S.y;
startDate = datenum('01-01-1990');
endDate = datenum('01-01-2019');
xData = linspace(startDate,endDate,360);
plot(xData,y);
set(gca,'XTick',xData);
datetick('x','yyyy')
masoumeh solgi
masoumeh solgi 2020년 5월 15일
thx so much ,it works

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

질문:

2020년 5월 15일

댓글:

2020년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by