generating monthly date series

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 个评论

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 个)

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 个评论

..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 Exchange 中查找有关 Time Series Objects 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by