Dates in MATLAB

1 次查看(过去 30 天)
Julia
Julia 2011-5-24
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');

采纳的回答

Arnaud Miege
Arnaud Miege 2011-5-24
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
  1 个评论
Julia
Julia 2011-5-24
Thanks very much. This is exactly what I was looking for.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Time Series Objects 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by