How to calculate average of Netcdf daily data

7 views (last 30 days)
I am able to read the netcdf file format. But how to calculate average? Suppose I have to calculate the average from 1st January to 31st January, then again 1th Feb. to 26th Feb. and so on.....Below is the program to read the values. and also attaching the data sets
%% New Program for Wind Vector data=netcdf.open('uwnd.sig995.2014.nc','NC_NOWRITE'); data1=netcdf.open('vwnd.sig995.2014.nc','NC_NOWRITE');
ug=netcdf.getVar(data,3,[0 0 0],[144 73 1],'double'); vg=netcdf.getVar(data1,3,[0 0 0],[144 73 1],'double'); lat1 = netcdf.getVar(data,0,0,73); lon1 = netcdf.getVar(data,1,0,144); ind = find(ug==9999); ug(ind) = NaN; vg(ind) = NaN; % end
[Lat, Lon] = meshgrid ( lat1, lon1 ); ws=sqrt(ug.^2+vg.^2);
% figure magnification
m_proj('Mercator','lon',[65 100],'lat',[5 40],'rect','on'); % Making projection % m_pcolor(Lon,Lat,ws); m_coast('patch',[.6 1 .6],'edgecolor','none'); m_grid('tickdir','out','yaxislocation','right',... 'xaxislocation','top','xlabeldir','end','ticklen',.02);
hold on
m_contourf(Lon,Lat,ws)
% m_plot(Lon,Lat,'color','k','linewidth',2.5);
m_quiver(Lon,Lat,ug,vg,50,'k');
hold off

Answers (1)

Chad Greene
Chad Greene on 16 Apr 2015
You can use downsample_ts. Syntax would be
ug_monthly = downsample_ts(ug,t,'monthly','mean');

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!