Calculating weekly mean from daily data.
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a netcdf file with u and v components for wind. I want to calculate the weekly averages of the u and v components based off of daily data.
so far I have
[y,mo,d] = datevec(dn);
xm = zeros(120,1);
for i = 1:120
if d = 1:7
xm(i) = mean(v_vector(d == i));
elseif d = 8:14
xm(i) = mean(v_vector(d == i));
elseif d = 15:23
xm(i) = mean(v_vector(d == i));
elseif d = 24:21
xm(i) = mean(v_vector(d == i));
end
dn is the date number. where 1 to 120 is the time increments from 1-Jan-2009 to 31-April-2009.
Thanks in advance
0 commentaires
Réponse acceptée
Eric Lin
le 18 Juin 2015
First, I would recommend finding a reliable method of determining the week number of a particular date. If you have access to R2014b or later, you can use the week function. An alternative is also available on MATLAB File Exchange.
From there, you can use a loop and logical indexing to find the means of each week:
%sample dates
t = datetime(2015,05,31):datetime(2015,06,18)
%week numbers
w = week(t)
%sample data
data = randi(10,1,19)
%mean for week 24
mean_24 = mean(data(w == 24))
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur NetCDF 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!