failure Reading Variables from multiple Netcdf files
Afficher commentaires plus anciens
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.
4 commentaires
MJFcoNaN
le 13 Juil 2022
Hello,
Please post full error messages and the relevant result of ncdisp
Tianchu Lu
le 13 Juil 2022
Walter Roberson
le 25 Juil 2022
Please show the output of
ncinfo(this_file)
for the first file.
Tianchu Lu
le 2 Août 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Standard File Formats dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
