# for loop in file

1 view (last 30 days)
Yu Jin Park on 7 Oct 2021
Answered: Image Analyst on 7 Oct 2021
Hi , I have problem with making for loop
I have 01~12 files and contain adt. I going to mean each month of adt and mean 1~12, annual adt
myFolder='C:\Users\yki\2000\01';
filepattern=fullfile(myFolder,'*.nc');
filelist=dir(filepattern);
nFiles=length(filelist);
for i=1:nFiles
filename1= fullfile(filelist(i).folder,filelist(i).name);
ncdisp(filename1);
end
myFolder='C:\Users\yki\2000\02';
filepattern=fullfile(myFolder,'*.nc');
filelist=dir(filepattern);
nFiles=length(filelist);
for i=1:nFiles
filename2= fullfile(filelist(i).folder,filelist(i).name);
ncdisp(filename2);
end
myFolder='C:\Users\yki\2000\03';
filepattern=fullfile(myFolder,'*.nc');
filelist=dir(filepattern);
nFiles=length(filelist);
for i=1:nFiles
filename3= fullfile(filelist(i).folder,filelist(i).name);
ncdisp(filename3);
end
myFolder='C:\Users\yki\2000\04';
filepattern=fullfile(myFolder,'*.nc');
filelist=dir(filepattern);
nFiles=length(filelist);
for i=1:nFiles
filename4= fullfile(filelist(i).folder,filelist(i).name);
ncdisp(filename4);
end
Jan on 7 Oct 2021

Image Analyst on 7 Oct 2021
I answered this in your duplicate question. You need to sum up the output of ncread() into a variable, then after the loop divide the sum by the number of files.