how to average seasonly?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have data set 141x49x300 (longitude,latitude,time), it contains data monthly average from 1995-2019. which mean 141x49x1 mean jan 1995 and 141x49x300 mean december 2019.
how do make average data every three month (dec, jan, feb) (mar, apr, may) and so on?
thanks
0 commentaires
Réponses (1)
dpb
le 6 Mar 2021
Modifié(e) : dpb
le 6 Mar 2021
This one is cute... :) Unfortunately, timetable won't accept a 2D array by row so have to do things directly...
t=linspace(datetime(1995,1,1),datetime(1995,12,31),300).'; % 300 elements between above start, stop
[r,c,p]=size(A); % sizes of data, A
M=(splitapply(@mean,reshape(A,r*c,[]).',findgroups(quarter(t)))); % compute means by quarter by columns
M=reshape(M.',r,c,[]); % reshape back to rxcx4
Substitute your real time vector for t, of course.
I did a trial here to check ordering...
t=linspace(datetime(1995,1,1),datetime(1995,12,31)).'; % only 100 instead of 300
A=randi([50 100],5,5,100); % dummy 5x5 data
M=(splitapply(@mean,reshape(A,25,100).',findgroups(quarter(t)))); % compute means 2D
>> M(:,1:3) % small piece to look at to check
ans =
78.4400 76.6000 75.3200
76.3200 73.2400 74.7200
71.6800 76.7200 83.7200
80.6000 74.3600 74.8000
>>
>> MM=reshape(M.',5,5,4);
>> whos MM
Name Size Bytes Class Attributes
MM 5x5x4 800 double
>> squeeze(MM(1,1,:))
ans =
78.44
76.32
71.68
80.60
>> squeeze(MM(2,1,:))
ans =
76.60
73.24
76.72
74.36
>>
0 commentaires
Voir également
Catégories
En savoir plus sur Octave dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!