필터 지우기
필터 지우기

How to i generate monthly sequence

조회 수: 3 (최근 30일)
Ayodele Ogunkoya
Ayodele Ogunkoya 2017년 12월 7일
답변: Akira Agata 2017년 12월 7일
I will like to generate number of days for each month in a calendar year by looping from January to December. The output of each monthly data will be saved. I want run the loop for all the 365 days in a year but have output for each month. For example: daystart=[1,32,60,91,121,152,182,213,244,274,305,335] and dayend = daystart + ndays.per.month(31 28 31 30 31 30 31 31 30 31 30 31).

채택된 답변

Akira Agata
Akira Agata 2017년 12월 7일
You don't need to use for-loop to obtain number of days for each month. The following example generates number of days per month from Jan. to Dec. in 2017.
t = datetime(2017,1,1):calmonths(1):datetime(2018,1,1);
daysPerMonth = days(diff(t));
The result is:
>> daysPerMonth
daysPerMonth =
31 28 31 30 31 30 31 31 30 31 30 31

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by