Effacer les filtres
Effacer les filtres

How to i generate monthly sequence

3 vues (au cours des 30 derniers jours)
Ayodele Ogunkoya
Ayodele Ogunkoya le 7 Déc 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).

Réponse acceptée

Akira Agata
Akira Agata le 7 Déc 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by