show month and year of a dataseries on the x axis

조회 수: 7 (최근 30일)
Locks
Locks 2013년 5월 5일
Hi,
I have this code which displays the respective year on the x axis
%SPX
SPX=dataSet(:,2);
%VIX
VIX=dataSet(:,3);
plotyy(dates,SPX,dates,VIX);
%datevc divides the date in different columns, first colum is the year,
%second the month and thrid the day
d=datevec(dates);
%Takes just the year (first column)
d=d(:,1);
%takes every year just once
[a,idx]=unique(d(:,1),'first');
set(gca,'xtick',dates(idx),'xticklabel',a)
[ax,h1,h2]=plotyy(dates,SPX,dates,VIX);
set(ax(1),'ycolor','k')
set(ax(2),'ycolor','k')
set(ax,'xtick',dates(idx),'xticklabel',a)
this worked well for a plot I needed, but I would like to plot a shorter time series where I can see the month as well as the year on the x axis
but there are only months on the x axis, what do I need to ammend in my code to be able to see both, month and year?

채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 5월 6일
Try using the following submission on FEX:
  댓글 수: 3
Shashank Prasanna
Shashank Prasanna 2013년 5월 7일
1) Give the FEX functions which is really 2 files along with your code, to others.
2) Create a subfunction in your code from the code in the dynamic datetick and distribute one file, instead of asking the end users to download it.
3) Go through the FEX submission and minimize the code specific to your application and include it your self.
Locks
Locks 2013년 5월 7일
ok, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2013년 5월 5일
If you click on the dateFormat link in the Input Arguments section of that help page you mention, so you will see that there are many different ways to format the labels, including some that show both month and year.
  댓글 수: 1
Locks
Locks 2013년 5월 5일
thanks, what I just do see is how I can adapt the existing code using those elements. could you give me a hint?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by