필터 지우기
필터 지우기

Date Axis

조회 수: 4 (최근 30일)
KKR
KKR 2011년 10월 8일
Hello Everyone,
Hope all is well. I need some help regarding, setting up Dates on x-axis. I have about 195 data points, and of course, I would like only 10-15 dates to show up on axis, as labels. Here is what I have tried to do, but somehow it is not working.
startDate = datenum('01-01-1995');
endDate = datenum('12-31-2010');
numtick = round((endDate - startDate)/365);
xData = linspace(startDate,endDate,numtick);
hold on
grid on
set(gca,'XTick',xData)
set(gca,'XTickLabel',datestr(xData,12))
p1 = plot(winmeanav,'-r');
p2 = plot(spxnav,'.-g');
p3 = plot(sprnav,'-k');
title('Time Series plot of NAVs between 1/1/1995 and
12/31/2010')
xlabel('Number of Months passed since 1/1/1995')
ylabel('NAVs')
Please let me know, if any extra information is needed. Any help would be very appreciated.
Thanks,

채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 8일
In your linspace() use numtick+1 .
For example suppose there was a difference of 1 year, 365 days. The serial date difference would be 365, round(365/365) would be 1, and then your current code would try to represent that 1 year range as a single value whereas you want one for the beginning and one for the end.
Also, you might have to cellstr() around the datestr() call.
  댓글 수: 1
KKR
KKR 2011년 10월 11일
Thank you Walter.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by