Date Axis
4 views (last 30 days)
Show older comments
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,
0 Comments
Accepted Answer
Walter Roberson
on 8 Oct 2011
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.
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!