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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 13 de Jul. de 2022
Editada: Fangjun Jiang el 13 de Jul. de 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 comentarios
Fangjun Jiang
Fangjun Jiang el 13 de Jul. de 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 el 13 de Jul. de 2022
That seemed to do the trick, thanks a million! New to this so I'm learning bit by bit!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by