Reading multiple NetCDF files in a Loop with multiple variables

7 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Krishna Zanwar
Krishna Zanwar il 22 Mar 2019
If you want to overwrite graphs of other months over this one you can use hold on.
If you want to divide the figure in different graphs for different months you can use sub plot.

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by