How to define sequence of dates between to dates on monthly time step?
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hydro
am 13 Dez. 2017
Beantwortet: Peter Perkins
am 19 Dez. 2017
Hello, I want to generate sequence of dates between two dates on monthly time step, however, couldnt figure a way out. I have tried various options such as datenum, datestr, datetime etc but could not solve my problem. Here is a sample of one trial.
StartDate= datetime(1981,01,01);
EndDate=datetime(2010,12,31);
formatOut='yyyy-mm';
Date=StartDate:EndDate;
Date=datetime(Date,formatOut);
I know it won't work as the number of the argument are wrong. but I want the date in the following format. Any help would be highly appreciated.
Jan-1981
Feb-1981
Mar-1981
-------
--------
Dec- 2010
0 Kommentare
Akzeptierte Antwort
Peter Perkins
am 19 Dez. 2017
Hydro, I think all you need is to add a step size of one calendar month (in your code you are stepping by one day):
StartDate = datetime(1981,01,01);
EndDate = datetime(2010,12,31);
Date = StartDate:calmonths(1):EndDate;
Date.Format = 'MMM-yyyy'
0 Kommentare
Weitere Antworten (1)
James Knowles
am 18 Dez. 2017
Here's a similar function I wrote for a similar purpose. It should put you on the write track and allow you to manipulate it for your own purposes.
function[m,y] = month_year(idx2,idx3)
month = ["Jan", "Feb", "March", "April", "May", "June", "July","Aug", "Sept", "Oct", "Nov", "Dec"]; year = [1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012];
m = month(idx2); y = year(idx3);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time 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!