generating monthly date series
Show older comments
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 Comment
André Damslora
on 16 Jun 2011
Answers (1)
Andrei Bobrov
on 16 Jun 2011
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 Comment
André Damslora
on 16 Jun 2011
Categories
Find more on Time Series Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!