Finding the mean of every 24 elements of 3rd dimension of a 3d array

2 views (last 30 days)
I have hourly weather data from 2000-2005 for an area giving a 241x121x52608 array. I am trying to condense the data down into the daily mean and so I'm looking to maintain the 241x121 matrix which denotes the location while condensing the 52608/24 into 2192 days in total (Including leap years)
I'm sure there is a simple way to do this but I'm new to Matlab so I'm struggling to come up with a solution.
Thanks

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 13 Jul 2022
Edited: Fangjun Jiang on 13 Jul 2022
Something like this. Try simple example to make sure the dimension, row, column are right.
a=ones(2,3,10);
b=mean(reshape(a,2,3,2,[]),4)
b =
b(:,:,1) = 1 1 1 1 1 1 b(:,:,2) = 1 1 1 1 1 1
  3 Comments
Fangjun Jiang
Fangjun Jiang on 13 Jul 2022
There are multiple ways. One example below. See doc for the arguments of calling reshape() and mean()
a=rand(2,3,10);
b=mean(reshape(a,2,3,5,[]),3);
b(1,1,1)
ans = 0.4785
c=a(1,1,:);
d=c(1,1,1)+c(1,1,2)+c(1,1,3)+c(1,1,4)+c(1,1,5);
e=d/5
e = 0.4785
Liam
Liam on 13 Jul 2022
That seemed to do the trick, thanks a million! New to this so I'm learning bit by bit!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!