Filter löschen
Filter löschen

How to i generate monthly sequence

2 Ansichten (letzte 30 Tage)
Ayodele Ogunkoya
Ayodele Ogunkoya am 7 Dez. 2017
Beantwortet: Akira Agata am 7 Dez. 2017
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).

Akzeptierte Antwort

Akira Agata
Akira Agata am 7 Dez. 2017
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by