Read every netcdf files in a folder

조회 수: 18 (최근 30일)
Valerio Gianforte
Valerio Gianforte 2020년 2월 26일
댓글: Valerio Gianforte 2020년 2월 26일
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);

채택된 답변

Bhaskar R
Bhaskar R 2020년 2월 26일
편집: Bhaskar R 2020년 2월 26일
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
Valerio Gianforte
Valerio Gianforte 2020년 2월 26일
Ok, now it does work. Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by