Average of 3d matrix
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
%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,[]) )
Yup, the zero due to the gap I wrote into the data does show up in the result.
1 Kommentar
KALYAN ACHARJYA
am 14 Dez. 2020
Thanks sir
Kategorien
Mehr zu Descriptive Statistics and Insights finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!