フィルターのクリア

Yearly average from monthly data

6 ビュー (過去 30 日間)
HA
HA 2018 年 11 月 29 日
コメント済み: Marek Harenda 2022 年 4 月 1 日
Hello,
It has been a while since I have made any new loops that I have not copied from old scripts, so I am a little out of practice. This question should be fairly easy for most to answer.
I have a data set with monthly data:
Size(A)=192,144,120
I would like to put this into ten, yearly averages:
Size(B)=192,144,10
I have just done it the long way around-
B(:,:,1)=mean(A(:,:,1:12),3);
B(:,:,2)=mean(A(:,:,13:24),3);
B(:,:,3)=mean(A(:,:,25:36),3);
B(:,:,4)=mean(A(:,:,37:48),3);
B(:,:,5)=mean(A(:,:,49:60),3);
B(:,:,6)=mean(A(:,:,61:72),3);
B(:,:,7)=mean(A(:,:,73:84),3);
B(:,:,8)=mean(A(:,:,85:96),3);
B(:,:,9)=mean(A(:,:,97:108),3);
B(:,:,10)=mean(A(:,:,109:120),3);
This works fine, but is a little tedious and I will be wanting to do this with much larger data sets in the coming months.
What is the best way to do this in a for loop?
Thank you!
  2 件のコメント
Dennis
Dennis 2018 年 11 月 29 日
Is there a specific reason for a loop? I think reshape should work aswell:
B=mean(reshape(A,192,144,12,[]),4);
HA
HA 2018 年 11 月 29 日
This does not quite give me what I want.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2018 年 11 月 29 日
s = size(A);
B = squeeze(mean(reshape(A,[s(1:2),12,s(3)/12]),3));
  2 件のコメント
HA
HA 2018 年 11 月 29 日
This Works well, thank you!
Marek Harenda
Marek Harenda 2022 年 4 月 1 日
Hello sir, can you help me with changing this code into calulation of the monthly avarage by which i mean calculating January, February, etc. mean from the whole dataset? I am asking you, because your code for annual mean is working with my data so I hope that I only need to do some little change to achieve my goal. I know that there are topics more related to my problem, but the proposals for solving it turned out not to be satisfactory for me. I see that in this case we need only to extract 12 consecutive months for each year, but in my case I probably need to extract every 12 month with 1 month shift so it is a bit more complicated for me.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by