Dates in MATLAB

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');

 Respuesta aceptada

Arnaud Miege
Arnaud Miege el 24 de Mayo de 2011

1 voto

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 comentario

Julia
Julia el 24 de Mayo de 2011
Thanks very much. This is exactly what I was looking for.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Language Fundamentals en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 24 de Mayo de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by