Reading netcdf files and variables backwards

3 visualizaciones (últimos 30 días)
Ana Corrochano
Ana Corrochano el 11 de Sept. de 2020
Respondida: Madhav Thakker el 15 de Sept. de 2020
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
KSSV
KSSV el 11 de Sept. de 2020
Why you are worried about reading in backwards?
Ana Corrochano
Ana Corrochano el 15 de Sept. de 2020
I have to do it for my project. At some point I have to simulate a particle tracking movement, and I need the particles starting moving in the end point

Iniciar sesión para comentar.

Respuestas (1)

Madhav Thakker
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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by