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