Reading multiple NetCDF files in a Loop with multiple variables
조회 수: 4 (최근 30일)
이전 댓글 표시
what I am trying to do is read multiple nc files of the format
'nh3nn_v2_2R_2016mmdd_AM.nc', then average a variable over a daily basis and then plot the daily average for each month.
- with mmdd as date, for example:
'nh3nn_v2_2R_20160301_AM.nc' < refers to March 01, 2016
'nh3nn_v2_2R_20160302_AM.nc' < refers to March 02, 2016
and so on...
I want to create Loop(s) that can read each file and take the daily average of Ammonia concentration and plots it for each month;
OUTPUT: to have in the end 12 plots, each one refers to one month of the year , with daily average.
> Check my code for the daily average of a single month
clear
myFolder = ('\\lx-jus\iasi-users\rimal\metopa\');
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
for k = 1:31
ncFilename = sprintf('nh3nn_v2_2R_201603%02d_AM.nc',k);
if isempty(ncFilename == 1)
continue;
else
ncfile=([myFolder ncFilename]);
long = ncread(ncfile,'longitude') ;
lat = ncread(ncfile,'latitude') ;
amon=ncread(ncfile,'column');
%averaging
amonavg(k)= nanmean(amon);
plot(amonavg)
axis([0 32,0e15 3e15])
xlabel('Daily Average')
ylabel ('NH3 Concentration (molec/cm^2)')
% Save figure
fname = '\\lx-jus\iasi-users\rimal\NH3 Plots\2016Monthly\';
saveas(gcf, fullfile(fname, '2016_03.png'), 'png');
end
end
> here is an example of a daily average output for March 2016
P.S I am very new to MATLAB
댓글 수: 0
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!