failure Reading Variables from multiple Netcdf files
3 次查看(过去 30 天)
显示 更早的评论
I am trying to read multiple different variables that is within a netcdf file, and almost extract the number that is associated with the variable that is listed. so what i have done is for it to loop for each variable, but i get an error displaying that one of the variable is not found even though it is on the nc file if i do ncdisp. could anyone help or optimise the code a little?
many thanks
ncvars={'duration','tecmin','tecmax','elevmin','elevmax','elev_tecmax','alt_elevmax','lat_elevmax','lon_elevmax','alt_tecmax','lat_tecmax','lon_tecmax','alt_start','lat_start','lon_start','alt_stop','lat_stop','lon_stop'};
projectdir= 'F:\cosmic_2_data_file';
dinfo=dir(fullfile(projectdir,'*.0001_nc'));
num_files=length(dinfo);
filenames=fullfile(projectdir,{dinfo.name});
durations=cell(num_files,1);
tecmins=cell(num_files,1);
tecmaxs=cell(num_files,1);
elevmins=cell(num_files,1);
elevmaxs=cell(num_files,1);
elevtecmaxs=cell(num_files,1);
altelevmaxs=cell(num_files,1);
latelevmaxs=cell(num_files,1);
lonelevmaxs=cell(num_files,1);
alttecmaxs=cell(num_files,1);
lattecmaxs=cell(num_files,1);
lontecmaxs=cell(num_files,1);
altstarts=cell(num_files,1);
latstarts=cell(num_files,1);
lonstarts=cell(num_files,1);
altstops=cell(num_files,1);
latstops=cell(num_files,1);
lonstops=cell(num_files,1);
for i=1 : num_files
this_file=filenames{i};
durations{i}=ncread(this_file,ncvars{1});
tecmins{i}=ncread(this_file,ncvars{2});
tecmaxs{i}=ncread(this_file,ncvars{3});
elevmins{i}=ncread(this_file,ncvars{4});
elevmaxs{i}=ncread(this_file,ncvars{5});
elevtecmaxs{i}=ncread(this_file,ncvars{6});
altelevmaxs{i}=ncread(this_file,ncvars{7});
latelevmaxs{i}=ncread(this_file,ncvars{8});
lonelevmaxs{i}=ncread(this_file,ncvars{9});
alttecmaxs{i}=ncread(this_file,ncvars{10});
lattecmaxs{i}=ncread(this_file,ncvars{11});
lontecmaxs{i}=ncread(this_file,ncvars{12});
altstarts{i}=ncread(this_file,ncvars{13});
latstarts{i}=ncread(this_file,ncvars{14});
lonstarts{i}=ncread(this_file,ncvars{15});
altstops{i}=ncread(this_file,ncvars{16});
latstops{i}=ncread(this_file,ncvars{17});
lonstop{i}=ncread(this_file,ncvars{18});
end
there are about 9400 .0001_nc files so i am hoping it can loop through and read the variables that i want and almost record that number and save it as a new cell.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!