daily data into weekly mean for whole year

7 views (last 30 days)
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.

Accepted Answer

Andrei Bobrov
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
Haa Andrew
Haa Andrew on 7 Sep 2017
Thank you for quick response, your answer in right in your own way but I want week-wise mean data. like 100x150x1 (First week), 100x150x1 (second week). simply i need week-wise separately data.. is it possible?
Andrei Bobrov
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.

Sign in to comment.

More Answers (0)

Categories

Find more on 기초 수학 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!