Calculating weekly mean from daily data.
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Eric Lin
2015-6-18
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!