Read every netcdf files in a folder
10 views (last 30 days)
Show older comments
Valerio Gianforte
on 26 Feb 2020
Commented: Valerio Gianforte
on 26 Feb 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);
0 Comments
Accepted Answer
Bhaskar R
on 26 Feb 2020
Edited: Bhaskar R
on 26 Feb 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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!