Monthly average from time series with daily values
이전 댓글 표시
I have 4 years of daily data in one file.
sla = ncread('data.nc','sla');
lon = ncread('data.nc','lon');
lat = ncread('data.nc','lat');
time = ncread('data.nc','time');
sla 181x101x1461 213668328 double
lat 101x1 404 single
lon 181x1 724 single
time 1461x1 5844 single
I want to calculate the monthly mean of the sla. The time vector comes out as
21916
21917
21918
21919
...
23376
%days since 1950-01-01
I want January to have 31 days, February to have 28/29 days, and so on. So I guess(?) I have to use
datestr(21916)
ans = 01-Jan-0060
I have tried to read through answers to similar questions, but that only made me more confused. Please explain on a basic level. Tnx!
답변 (3개)
DV = datevec(double(time) + datenum('01-Jan-1950')); % EDITED
Now DV is a [1461 x 6] matrix. Now:
MonthIndex = DV(:, 1) * 12 + DV(:, 2)
gives an index for each month. accumarray will do the rest.
Chad Greene
2014년 11월 5일
편집: Chad Greene
2014년 11월 5일
t_daily = datenum(1950,1,1,double(time),0,0);
[sla_monthly,t_monthly] = downsample_ts(sla,t_daily);
Peter Perkins
2014년 11월 5일
K_r1, if you have access to MATLAB R2014b, there are some new data types that make this more straight-forward:
>> dt0 = datetime('1950-01-01')
dt0 =
01-Jan-1950
>> dt = dt0 + caldays([21916:250:23376]')
dt =
02-Jan-2010
09-Sep-2010
17-May-2011
22-Jan-2012
28-Sep-2012
05-Jun-2013
>> months = between(dt0,dt,'months')
months =
720mo
728mo
736mo
744mo
752mo
761mo
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!