Anyone has a way of generating a monthly series (say 1Feb2011 to 1Nov2015) without having to use a loop?
One could imagine a function like linspace:
dateseries(startdate,enddate,frequency)
e.g.
t = dateseries('1Feb2011','1Nov2015','monthly')
It's fairly easy to go via a datevec, but I think that there is a need for such a functionality.
The function should return a vector of datenums.
Kind regards, A. Damslora

1 件のコメント

André Damslora
André Damslora 2011 年 6 月 16 日
One illustrating function:
function m = fillmonthly(d0,d1)
dv_start = datevec(d0);
dv_end = datevec(d1);
tmp = (1:[dv_end-dv_start]*[12 1 0 0 0 0]')'-1;
u = ones(size(tmp));
m = datenum([dv_start(1)*u, dv_start(2)+tmp, u*[1 0 0 0]]);
Call example:
datestr(fillmonthly('1nov2012','1feb2014'),'ddmmmyy')

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

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 6 月 16 日

0 投票

use Financial Toolbox
doc datemnth
doc months
COD:
dated = {'01-Feb-2011','01-Nov-2015'};
t = datemnth(dated{1}, (0: months(dated{:}))')
more variant without Financial Toolbox
v = datevec({'01-Feb-2011','01-Nov-2015'});
out = datenum(cumsum([v(1,1:3);ones(diff(v(:,1:3))*[12 1 0 ]',1)*[0 1 0 ]]));

1 件のコメント

André Damslora
André Damslora 2011 年 6 月 16 日
..OK, Thanks :)
I suspected they had to add it in FTB as most financial packages have it. But honestly these are so simple routines that I think Mathworks could make them available in the basic module.
I don't see any gains for Mathworks by hiding this in a toolbox - it only annoys the customers who have to make their own versions.

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

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

製品

質問済み:

2011 年 6 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by