how can I take monthly data from a 20 year dataset
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a 20 year data set of surface solar radiation (ssr) from Copernicus ERA5 and want to break down the data into the seasonal averages to evaluate the impact of ENSO events
I am using the find function and am able to pull out single months for comparison but not the data between a range of months
this is the code I have used to pull out December, I can replicate this for all 12 months but ideally I would like March-June and November-February
Thanks In Advance
k=find(dates(:,2)==12; % corrected as noted by OP -- dpb
avg_dec=mean(ssr(:,:,k),3);
avg_dec=avg_dec';
x=datenum(dates(:,1:3));
k=dates(:,2)==12
x2=datenum(dates(k,1:3));
avg_dec=avg_timeseries(k);
2 commentaires
dpb
le 17 Mai 2021
Create a grouping variable of the two sections of the year and then use rowfun or splitapply
Are you referenced from N or S hemisphere? Is June summer or winter by reference for grouping variable identification?
BTW, use the new datetime class, not the deprecated datenum
Oh...just noticed -- what's the two levels/redundant (almost) code here for?
You start with k being the indices of planes in a 3D array ssr and average over those, then repeat with a logical vector of the same dates, just as the logical addressing vector instead of indices which is the same thing, effectively.
Then you use that to address an undefined variable avg_timeseries
I guess somewhere in code not shown you have averaged across the avg_dec 2D array to get a single value for December across the array of measured locations?
Think we need a better description of the data storage and exactly what average you're looking for to be able to write specific code.
Réponses (1)
Cris LaPierre
le 17 Mai 2021
If you convert your dates to datetimes, you can use groupsummary. There, you can specify how you want to group the data. With datetimes, you can group by second, minute, hour, day, week, month, year, etc. See here.
0 commentaires
Voir également
Catégories
En savoir plus sur Dates and Time 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!