Clear Filters
Clear Filters

Read every netcdf files in a folder

14 views (last 30 days)
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);

Accepted Answer

Bhaskar R
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)

Categories

Find more on Agriculture in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!