Calculating weekly mean from daily data.
조회 수: 6 (최근 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!