Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

plot chart with the respective date on the x axis

Asked by Locks

Locks (view profile)

on 24 Mar 2013

Hi,

I have a data set with two columns, in the second there are daily historical data which I would like to plot. This is no problem. In the first column of the data set, there is the respective data which should be displayed on the x-axis.

The thing is that the whole data set consists of more than 5000 rows and I do not want to have displayed 5000 dates on the x-axis but just the years, as follows

2000 2001 2002 2003 2004 2005 2006 2007 2008 2009

In excel that is no big deal but I do not know how to do that in Matlab

0 Comments

Locks

Locks (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 24 Mar 2013
Edited by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 24 Mar 2013
Accepted answer

Look at this example

dates=datenum('01/01/2000'):datenum('01/01/2009')
y=sin(0.01*dates)
plot(dates,y)
d=datevec(dates)
[a,idx]=unique(d(:,1),'first')
set(gca,'xtick',dates(idx),'xticklabel',a)

11 Comments

Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 24 Mar 2013

Use

 dates=datenum(VIXdate)
Locks

Locks (view profile)

on 24 Mar 2013

that's working, thanks!

Locks

Locks (view profile)

on 24 Mar 2013

sorry, I have just seen now that there is still one problem. the date should be displayed at 1.1. of each year not at the end of a year, how can I change that?

Azzi Abdelmalek

Azzi Abdelmalek (view profile)

Answer by Will Forfang

Will Forfang (view profile)

on 24 Mar 2013

Sounds like you need to adjust the "ticks" of your x-axis.

Check this out: http://www.mathworks.com/help/matlab/creating_plots/setting-axis-parameters.html

0 Comments

Will Forfang

Will Forfang (view profile)

Contact us