Read every netcdf files in a folder

10 ビュー (過去 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 Center および File ExchangeAgriculture についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by