Reading netcdf files and variables backwards
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Madhav Thakker
2020 年 9 月 15 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で NetCDF についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!