How to create monthly average from daily data?
3 次查看(过去 30 天)
显示 更早的评论
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
2016-2-6
How do you know which column is which date? Must have a corresponding date somewhere, what's its format?
回答(2 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!