Calculating weekly mean from daily data.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
lreplo
am 17 Jun. 2015
Beantwortet: Eric Lin
am 18 Jun. 2015
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 Kommentare
Akzeptierte Antwort
Eric Lin
am 18 Jun. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu NetCDF 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!