Averaging monthly using accumarray for two arrays?
이전 댓글 표시
I realize this is a question asked often, but there doesnt appear to be a easy solution.
So I'm trying to average daily data to monthly, across a multitude of years. My data is in a 1000x5 array, with columns being year, month, day, datestr and catch. The number of rows dedicated to each day varies. I'd like to average monthly, and if possible keep the month/year columns.
so far i havent had much success:
data example:
xx(1,:) = 1993 1 26 727942 365
my code currently looks like:
[dontcare, m] = month(xx(:,4));
y = year(xx(:,4));
ii = strcat(numstr(y),m);
for YY = 1:size(xx(:,1)); % So running through the whole of the data set
for jj = unique(ii, 'rows')
month_av = accumarray(ii('rows'), xx(:,5),[],@mean); % This doesnt work obviously
end
end
This doesnt work because, i know, the logic is wrong, but i'm unsure of how to fix it - i need to refernece the same rows in two arrays (ii and xx) to average xx for the unique values in ii.
Any ideas would be much appreciated.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!