Read every netcdf files in a folder

11 vues (au cours des 30 derniers jours)
Valerio Gianforte
Valerio Gianforte le 26 Fév 2020
folderData = 'D:\Valerio\data\TEST';
filePattern = fullfile(folderData, '*.nc');
ncfiles = dir(filePattern);
nFiles = length(ncfiles);
for i = 1:nFiles
ncdisp(ncfiles(i).name);
%file = 'ww3_outf_198501.nc';
%ncdisp(file);
lon = ncread(ncfiles(i),'x');
lat = ncread(ncfiles(i),'y');
%latitudine e longitudine
H_s = ncread(ncfiles(i),'Hs');
T_m = ncread(ncfiles(i),'Tm');
D_m = ncread(ncfiles(i),'Dm');
time1 = ncread(ncfiles(i),'time1'); %anno, mese e giorno
time2 = ncread(ncfiles(i),'time2'); %ore, minuti e secondi
end
Hi everyone,
I have to read and do some operation on the every netcdf files in a folder. I did for loop to read all the file but it stops on the command 'ncdisp' and I obtain the error below.
Is there someone that can help me? Thank you so much.
Error using internal.matlab.imagesci.nc/openToRead (line 1272)
Could not open ww3_outf_198502.nc for reading.
Error in internal.matlab.imagesci.nc (line 121)
this.openToRead();
Error in ncdisp (line 62)
ncObj = internal.matlab.imagesci.nc(ncFile);

Réponse acceptée

Bhaskar R
Bhaskar R le 26 Fév 2020
Modifié(e) : Bhaskar R le 26 Fév 2020
Try this with full path filename
folderData = 'D:\Valerio\data\TEST';
filePattern = fullfile(folderData, '*.nc');
ncfiles = dir(filePattern);
nFiles = length(ncfiles);
for i = 1:nFiles
filename = fullfile(ncfiles(i).folder, ncfiles(i).name);
ncdisp(filename);
%file = 'ww3_outf_198501.nc';
%ncdisp(file);
lon = ncread(filename,'x');
lat = ncread(filename,'y');
%latitudine e longitudine
H_s = ncread(filename,'Hs');
T_m = ncread(filename,'Tm');
D_m = ncread(filename,'Dm');
time1 = ncread(filename,'time1'); %anno, mese e giorno
time2 = ncread(filename,'time2'); %ore, minuti e secondi
end
  1 commentaire
Valerio Gianforte
Valerio Gianforte le 26 Fév 2020
Ok, now it does work. Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Agriculture dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by