Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

regarding files from directory

2 Ansichten (letzte 30 Tage)
Uday
Uday am 19 Okt. 2011
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I have 156 different files in one folder , out of which I need to read first 13 files only and then start reading from 14 to 26 so on till 156. e.g v_1970_ch4.nc v_1970_ch4_1.nc v_1970_ch4_2.nc . .
v_1970_ch4_13.nc
v_1980_ch4_1.nc v_1980_ch4_1.nc v_1980_ch4_2.nc . .
v_1980_ch4_13.nc
I need to add data together for every 13 files, so how I can set for loop ?
[Edit: moved code from comment]
dir_list =dir('v41_CH4*');
k=0;
for i=1:length(dir_list)
vec1=zeros(720,360);
for j =1:13
k=k+1;
ncid=netcdf.open(dir_list(k).name,'NOWRITE');
latid=netcdf.inqVarID(ncid,'lat');
latitude=double(netcdf.getVar(ncid,latid));
lonid=netcdf.inqVarID(ncid,'lon');
longitude=double(netcdf.getVar(ncid,lonid));
emi_ch4id=netcdf.inqVarID(ncid,'emi_ch4');
ch4=double(netcdf.getVar(ncid,emi_ch4id));
vec1=(vec1+ch4);
end
end
  1 Kommentar
Jan
Jan am 19 Okt. 2011
It is always a good idea to post, what you have done so far. Then we can re-use as much code as possible and do not confuse you by using different names for variables etc.

Antworten (1)

Jan
Jan am 19 Okt. 2011
Does alphabetical sorting create the wanted order? Or are there problems like in:
sort({'1', '2', '9', '10', '11'})
>> '1' '10' '11' '2' '9'
  1 Kommentar
Uday
Uday am 19 Okt. 2011
I think in this case alphabetical order will not work because every time I need to read 1:13 and then 14:26.......156

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by