Monthly average from time series with daily values
4 views (last 30 days)
Show older comments
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!
0 Comments
Answers (3)
Chad Greene
on 5 Nov 2014
Edited: Chad Greene
on 5 Nov 2014
t_daily = datenum(1950,1,1,double(time),0,0);
[sla_monthly,t_monthly] = downsample_ts(sla,t_daily);
0 Comments
Peter Perkins
on 5 Nov 2014
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
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!