how to calculate 3D netcdf in matlab?

1 回表示 (過去 30 日間)
Habtamu Tsegaye
Habtamu Tsegaye 2023 年 2 月 3 日
I have 300-by-240-by-365 3D netcdf file for 16 years rainfall data. I need to have mean monthly data which contains 300-by-240-by-12. how can I do this?
here is my trial script
clear all;
MP2(1:300,1:240,1:12)=0; % in case of IMERG lat is arranged in row where as lon is arranged in column((lat:lon,year)=0) is Monthly Precipitation (MP) with zero intial matrix to start for loop
for yy=2002:2017 % the year from 2002 to 2017
for mm=1:12
ap2(1:300,1:240)=0;
E = eomday(yy,mm);
dy=YYYYMMDD2doy(yy,mm,1);
hits1 = ['D:\Rainfall_Data_from_Satelite\CHIRPS/','chirps-v2.0.',num2str(yy,'%02d'),'.days_p05.nc'];
fe = dir(hits1);
ncid = netcdf.open(hits1);
lat=netcdf.getVar(ncid,0,'single'); % latitude
lon=netcdf.getVar(ncid,1,'single'); % longitude
p1=ncread(hits1,'precip',[4269,1061,dy],[300,240,E]);% days in a month
p1_sum=nansum(p1,3); % a monthly rainfall using sum of daily data
% scale=netcdf.getAtt(ncid,3,'scale_factor');
% offset=netcdf.getAtt(ncid,3,'add_offset');
netcdf.close(ncid);
end
MP2(:,:,mm)=p1_sum;
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by