Info

此问题已关闭。 请重新打开它进行编辑或回答。

regarding files from directory

1 次查看(过去 30 天)
Uday
Uday 2011-10-19
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Jan
Jan 2011-10-19
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.

回答(1 个)

Jan
Jan 2011-10-19
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 个评论
Uday
Uday 2011-10-19
I think in this case alphabetical order will not work because every time I need to read 1:13 and then 14:26.......156

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by