How to define sequence of dates between to dates on monthly time step?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hydro
el 13 de Dic. de 2017
Respondida: Peter Perkins
el 19 de Dic. de 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 comentarios
Respuesta aceptada
Peter Perkins
el 19 de Dic. de 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 comentarios
Más respuestas (1)
James Knowles
el 18 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!