Reading netcdf files and variables backwards
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a number of files, each file has numerous variables that I need to read backwards (each file corresponds to one day, I need to read all the info in each file backwards and I also need to start reading from file number 15 to file number 1). So far, I've been able to start reading from file 15 to file 1. But when reading the variables also backwards I'm still stuck ( In my code, I'm selecting just 1 variable to verify it's working and I get all the data backwards). Still, I don't know what I'm doing wrong in here.
clear myFolder = ('C:\modelana\netcdf_2019'); fileList = dir([myFolder '*.nc']);
for k = length(fileList):-1:1 %read filelist backwards if isempty(fileList) continue; else baseFileName = fileList(k).name; fullFileName = fullfile(myFolder, baseFileName);
ncfile=[myFolder fileList(k).name];
s{k} = ncread(ncfile,'salinity');
for s = length(k):-1:1 %read contents of array k backwards
if isempty(k)
continue;
else
baseFileName = k(s).name;
fullFileName = fullfile(myFolder, baseFileName);
ncfile = [myFolder k(s).name];
end
end
end
%t{k} = ncread(ncfile,'temp');
%u{k} = ncread(ncfile,'u');
end '''
2 comentarios
Respuestas (1)
Madhav Thakker
el 15 de Sept. de 2020
Hi Ana,
I understand that you want to read the variables backward. I see that there is some problem with naming of the variables.
for k = length(fileList):-1:1 %read filelist backwards if isempty(fileList) continue; else baseFileName = fileList(k).name; fullFileName = fullfile(myFolder, baseFileName);
k is an integer here, which is causing problems in,
for s = length(k):-1:1 %read contents of array k backwards
if isempty(k)
continue;
else
baseFileName = k(s).name;
fullFileName = fullfile(myFolder, baseFileName);
ncfile = [myFolder k(s).name];
end
end
In this loop, there are multiple references to variable k. This should be s{k} instead.
Hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre NetCDF en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!