How to create monthly average from daily data?

조회 수: 7 (최근 30일)
reyadh Albarakat
reyadh Albarakat 2016년 2월 5일
답변: ABHILASH SINGH 2020년 3월 13일
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
dpb
dpb 2016년 2월 6일
How do you know which column is which date? Must have a corresponding date somewhere, what's its format?

댓글을 달려면 로그인하십시오.

답변 (2개)

dpb
dpb 2016년 2월 7일
편집: dpb 2016년 2월 7일
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 2020년 3월 13일

카테고리

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