how to do average over third dimension?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lilya
am 26 Jul. 2021
Kommentiert: Star Strider
am 26 Jul. 2021
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 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Jul. 2021
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)
The ‘out’ variable now has 4 blocks of 6-hour averages
.
8 Kommentare
Star Strider
am 26 Jul. 2021
As always, my pleasure!
(Sorry for the delay — I was off doing other things.)
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!