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

2 vues (au cours des 30 derniers jours)
Liam
Liam le 13 Juil 2022
Commenté : Liam le 13 Juil 2022
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

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 13 Juil 2022
Modifié(e) : Fangjun Jiang le 13 Juil 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 commentaires
Fangjun Jiang
Fangjun Jiang le 13 Juil 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 le 13 Juil 2022
That seemed to do the trick, thanks a million! New to this so I'm learning bit by bit!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by