Dates in MATLAB
2 views (last 30 days)
Show older comments
I was wondering if someone could please help me with dates in MATLAB. I have time series data for a certain stock price. The observations are monthly and go from January 2001 to March 2011 i.e. I have 123 observations. I need to graph this data in such a way that I use all 123 observations on the y-axis but my x-axis only has year at the first observation (2001) and then year after 11 other observations (2002) and so on. Below is the code that I wrote based on help files. The problem here is that the year appears at every single observation and so it's impossible to determine what's on the x-axis when you look at the graph. I need the year to appear at every 12th observation. I appreciate all the help.
MATLAB Code:
Walmart_S = xlsread('US_Share_Prices', 'c75:c197');
startDate = datenum('01-01-2001');
endDate = datenum('03-31-2011');
xData = linspace(startDate,endDate,123);
plot(xData,Walmart_S);
set(gca,'XTick',xData);
datetick('x','yyyy','keepticks');
0 Comments
Accepted Answer
Arnaud Miege
on 24 May 2011
This is because of the way you set XTick. Use this instead:
set(gca,'XTick',linspace(startDate,endDate,11))
datetick('x','yyyy','keepticks');
HTH,
Arnaud
More Answers (0)
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!