how to do average over third dimension?

22 ビュー (過去 30 日間)
Lilya
Lilya 2021 年 7 月 26 日
コメント済み: Star Strider 2021 年 7 月 26 日
Hi all,
I have multiple 3D matrices with the dimension of 21*41*24 for each which 24 (third dimension) is 24 hours.
I wanted to calculate 6 hours average for the third dimension.
Where I am mistaken?
NHours=size(ucom,3);
NDays=NHours/6;
out = nanmean(permute(reshape(ucom,[6,NDays]),[2,1,3]),3);
  2 件のコメント
KSSV
KSSV 2021 年 7 月 26 日
Read about mean there is option to get mean in any dimension.
Lilya
Lilya 2021 年 7 月 26 日
OK..Thank you :)

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

採用された回答

Star Strider
Star Strider 2021 年 7 月 26 日
Taking a slightly shorter example, try something like this —
% ucom = randi(9,21,41,24);
ucom = randi(9, 3, 4, 24);
sz_ucom = size(ucom);
ucomr = reshape(ucom,sz_ucom(1),sz_ucom(2),[],6);
out = nanmean(ucomr,4)
out =
out(:,:,1) = 5.6667 5.5000 4.8333 3.1667 5.8333 4.5000 5.6667 4.0000 5.8333 5.1667 5.0000 4.5000 out(:,:,2) = 3.8333 6.0000 4.5000 6.0000 6.0000 5.1667 5.6667 2.5000 3.1667 6.0000 5.3333 5.3333 out(:,:,3) = 3.8333 3.6667 6.3333 5.3333 4.1667 6.0000 5.5000 5.6667 3.6667 5.0000 4.1667 6.3333 out(:,:,4) = 5.5000 5.5000 4.1667 2.6667 3.1667 3.6667 4.8333 4.8333 7.0000 3.8333 5.5000 6.3333
The ‘out’ variable now has 4 blocks of 6-hour averages
.
  8 件のコメント
Lilya
Lilya 2021 年 7 月 26 日
It works!!
Much much appreciated.
Star Strider
Star Strider 2021 年 7 月 26 日
As always, my pleasure!
(Sorry for the delay — I was off doing other things.)
.

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

その他の回答 (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