Dates in MATLAB

2 visualizzazioni (ultimi 30 giorni)
Julia
Julia il 24 Mag 2011
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');

Risposta accettata

Arnaud Miege
Arnaud Miege il 24 Mag 2011
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 Commento
Julia
Julia il 24 Mag 2011
Thanks very much. This is exactly what I was looking for.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by