daily data into weekly mean for whole year
7 views (last 30 days)
Show older comments
I have 3D matrix 100x150x365 (Column 3 shows number of days). I want to get weekly mean in loop with same first two dimensions. At the end I need 100x150x53 (53 weeks). Please share your experience to solve this problem.
0 Comments
Accepted Answer
Andrei Bobrov
on 7 Sep 2017
Edited: Andrei Bobrov
on 7 Sep 2017
Let A - your array
[m,n,k] = size(A);
p = 7;
i3 = ceil((1:k)'/p);
[ii,jj,kk] = ndgrid(1:m,1:n,i3);
out = accumarray([ii(:),jj(:),kk(:)],A(:),[],@mean);
2 Comments
Andrei Bobrov
on 7 Sep 2017
Edited: Andrei Bobrov
on 7 Sep 2017
in my case: first week -> out(:,:,1); second week -> out(:,:,2) and etc.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!