FIGURE: plot monthly data and only present the years

4 Ansichten (letzte 30 Tage)
Lily
Lily am 26 Nov. 2012
Hi I'm trying to plot monthly data and only present the years on the x-axis. Is this method correct?
startdate = datenum('31-01-2002','dd-mm-yyyy')
enddate = datenum('31-12-2010','dd-mm-yyyy')
dt = linspace(startdate,enddate,108);
data = rand(numel(dt),1);
plot(dt,data)
datetick('x','yyyy','keepticks')
  2 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 26 Nov. 2012
It's 96 months how will you represent them?
Lily
Lily am 27 Nov. 2012
I'm trying to plot monthly (x-axis) stock prices (y-axis) and I can't seem to get the x-axis with correct labeling, that is counting it in months. The first thing I tried was (see below) but it didn't work. Dou have a better solution? :)
startdate = datenum('01-2002','mm-yyyy');
enddate = datenum('12-2011','mm-yyyy');
dt = linspace(startdate,enddate,120);
data = rand(numel(dt),1); %random data
plot(dt,data)
hold on
datetick('x','yyyy','keepticks');
hold off

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 27 Nov. 2012
Bearbeitet: Azzi Abdelmalek am 27 Nov. 2012
try this
dt=datenum(2002,(1:120),1)

Weitere Antworten (0)

Kategorien

Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by