Error "Could not open file 'ncfiles'". when using a for loop to open ncfiles

2 vues (au cours des 30 derniers jours)
Hi
I have 469 ncfiles and I open them in a loop:
ncfiles = dir('*.nc') ;
Nfiles = length(ncfiles) ;
for i = 1:Nfiles;
ncdisp(ncfiles(i).name) ;
ncid=netcdf.open('ncfiles','NOWRITE');
varname = netcdf.inqVar(ncid);
[ndim, nvar, natt, unlim]=netcdf.inq(ncid);
end
But when I run the code I got the error when I used ncid:
Error using netcdf.open (line 52)
Could not open file 'ncfiles'.
Error in Blocking (line 9)
ncid=netcdf.open('ncfiles','NOWRITE');
I hope you can help me!

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Déc 2018
your file name is stored in ncfiles(i).name rather than being the literal file name 'ncfiles'
  9 commentaires
Jonas Damsbo
Jonas Damsbo le 7 Déc 2018
Such like that?
%Indlæser alle filer fra folderen
ncfiles = dir('*.nc') ;
Nfiles = length(ncfiles) ;
for i = 1:Nfiles;
ncdisp(ncfiles(i).name) ;
ncid=netcdf.open(ncfiles(i).name,'NOWRITE');
%[ndim, nvar, natt, unlim]=netcdf.inq(ncid);
netcdf.close(ncid);
end
lat = cell(Nfiles, 1);
lon = cell(Nfiles, 1);
time = cell(Nfiles, 1);
z = cell(Nfiles, 1);
for i = 1:Nfiles
lon(i) = ncread(ncfiles(i).name, 'longitude'); %nx = length(lon(i));
lat(i) = ncread(ncfiles(i).name, 'latitude'); %ny = length(lat(i));
time(i) = ncread(ncfiles(i).name, 'time'); %nt = length(time(i));
z(i) = ncread(ncfiles(i).name, 'z'); %nz = length(z(i));
end
Because now I get the error "Conversion to cell from single is not possible."

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Agriculture dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by