필터 지우기
필터 지우기

How to define sequence of dates between to dates on monthly time step?

조회 수: 15 (최근 30일)
Hydro
Hydro 2017년 12월 13일
답변: Peter Perkins 2017년 12월 19일
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

채택된 답변

Peter Perkins
Peter Perkins 2017년 12월 19일
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'

추가 답변 (1개)

James Knowles
James Knowles 2017년 12월 18일
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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by