Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

regarding files from directory

2 vues (au cours des 30 derniers jours)
Uday
Uday le 19 Oct 2011
Clôturé : MATLAB Answer Bot le 20 Août 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 commentaire
Jan
Jan le 19 Oct 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.

Réponses (1)

Jan
Jan le 19 Oct 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 commentaire
Uday
Uday le 19 Oct 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

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by