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.

更多回答(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