How to create monthly average from daily data?

5 views (last 30 days)
Hi Everybody;
I have used daily data for 34 years, I have one row and 11690 columns, by the way I have some missing data in 1994 (the last three months) and 2000 (I have only last tow months). I would like to make monthly average and then for Normal year and Leap year.
Thank you in advance.
  1 Comment
dpb
dpb on 6 Feb 2016
How do you know which column is which date? Must have a corresponding date somewhere, what's its format?

Sign in to comment.

Answers (2)

dpb
dpb on 7 Feb 2016
Edited: dpb on 7 Feb 2016
As noted in the comment, since the problem is insolvable without having the dates in some form, I'll just assume you can create the date number vector associated with each observation from whatever format you do have.
Given that as variable dn, then to accumulate a summation over the months first must get a sequential month indicator over the length of the series.
[~,mo]=datevec(dn); % the month of each observation from its corresponding date number
ix=cumsum(diff([0; mo])~=0); % the sequential index of month for each element
mnbymo=accumarray(ix,v,[],@mean); % the means by the months
Note the above will account for missing values simply by accumulating the values that are present for a given month; it will not indicate which are short months or the like...you'll have to do that by testing for spacing between the elements of ix that don't match the expected number of days for the month and year (altho it sounds as though you may already know which aren't complete so you can probably just convert that known info to the sequential month based on position(+)).
ADDENDUM
(+)NB: The above will not account for completely missing months excepting by there being a sequential month for each existing month in the date number vector. The accumlator as above treats every jump in month as an increment so if there are missing months in their entirety the accumlated series will shift down one in a numerical sense from where it would be based on a full 12-months/calendar year.

ABHILASH SINGH
ABHILASH SINGH on 13 Mar 2020

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!