フィルターのクリア

Average of 3d matrix

10 ビュー (過去 30 日間)
mohamad shirgholami
mohamad shirgholami 2020 年 12 月 14 日
編集済み: KALYAN ACHARJYA 2020 年 12 月 14 日
hi
I have 3D matrix with dimension (61,57,365) the 365 is daily time. I want to do a monthly average overtime to get (61,57,12). But the number of days each month is different. I would be grateful for your help

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 14 日
編集済み: KALYAN ACHARJYA 2020 年 12 月 14 日
#One Way
m=cumsum([0,31,28,31,30,31,30,31,31,30,31,30,31]);
data=rand(61,57,365); %Sample Data
month_ave=zeros(1,12)
for i=1:12
data1=data(:,:,m(i)+1:m(i+1));
month_ave(i)=mean(data(:));
end
month_ave
  7 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 14 日
Mohmad comments moved here
hi
What do you mean by index?
if index=[31,28,31,30,31,30,31,31,30,31,30,31] , all arrays of output matrix become zeros.
thanks.
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 14 日
編集済み: KALYAN ACHARJYA 2020 年 12 月 14 日
In this case it added 2 more loops,definitely which isn't an efficient/easiest way out.
m=cumsum([0,31,28,31,30,31,30,31,31,30,31,30,31]);
data=rand(61,57,365); %Sample Data
ave_data=zeros(61,57,12);
for r=1:61
for c=1:57
for d=1:12
data1=data(r,c,m(d)+1:m(d+1));
ave_data(r,c,d)=mean(data1(:));
end
end
end
ave_data

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 12 月 14 日
%Sample Data
data = rand(61,57,365);
data(:,:,200:250) = 0;
%the work
m = cumsum([0,31,28,31,30,31,30,31,31,30,31,30,31]);
month_ave = zeros(size(data,1), size(data,2), 12);
for month = 1 : 12
start_at = m(month)+1;
end_at = m(month+1);
month_ave(:,:,month) = mean(data(:,:,start_at:end_at), 3);
end
%show results
format long g
mat2str( reshape(month_ave(1,1,:),1,[]) )
ans = '[0.522259150104234 0.461364358148672 0.471978553723879 0.528354847707762 0.522092627671028 0.424906953694024 0.29348062051905 0 0.382149020541875 0.38378942552417 0.454583006879377 0.543602194085556]'
Yup, the zero due to the gap I wrote into the data does show up in the result.
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 14 日
Thanks sir

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by