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일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

제품

질문:

2011년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by