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

2 ビュー (過去 30 日間)
Liam
Liam 2022 年 7 月 13 日
コメント済み: Liam 2022 年 7 月 13 日
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

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 7 月 13 日
編集済み: Fangjun Jiang 2022 年 7 月 13 日
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 件のコメント
Fangjun Jiang
Fangjun Jiang 2022 年 7 月 13 日
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 2022 年 7 月 13 日
That seemed to do the trick, thanks a million! New to this so I'm learning bit by bit!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by