Plot question: Monthly data on yearly axis

1 回表示 (過去 30 日間)
John Smith
John Smith 2011 年 4 月 8 日
Hi all,
I would like to ask how is it possible to plot monthly data on an axis that displays years on the axis.
Many thanks!
  1 件のコメント
Matt Tearle
Matt Tearle 2011 年 4 月 9 日
Can you elaborate on what format your data is in? Do you have a time series of monthly observations? Are they serial date numbers, or just integer values, or years with fractional parts, or what? An example would help.

サインインしてコメントする。

回答 (3 件)

Oleg Komarov
Oleg Komarov 2011 年 4 月 9 日
You were using datenum incorrectly:
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')

Royi Avital
Royi Avital 2011 年 4 月 9 日
If I'm guessing right what's your difficulty the fact that plot doesn't show "NaN" values should assist you.
Meaning, Pad your data to the 'x' length with "NaN".

John Smith
John Smith 2011 年 4 月 9 日
Thanks for the answers.
Let me give you an example: I got a matrix lets say data with 108 observations and I use the following commands to plot this data and then update the x axis with dates:
startdate = datenum('31-01-2002')
enddate = datenum('31-12-2010')
dt = linspace(startdate,enddate,12);
plot(dt,data)
set(gca,'XTick',dt)
datetick('x','yyyy','keepticks')
tried also: startdate=datenum('01-2002') enddate=datenum('12-2010')
any ideas?
Thanks

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by