Read files from filenames stored in cell array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi
I have a lot of netCDF files (>100,000) of small size (~20 kb). I have a cell array read from a .txt file that lists each filename, including the full file directory, of which there 3 subdirectories with respect to my root folder e.g. dir/dir/dir/filename.nc . I want to read variables from each netCDF file (they have identical variables) by calling the filename listed in the cell array from my working folder. I am struggling on how to convert the text in the cell array into a readable file identifier. I have used textscan to read the filenames into a cell array, and tried both dir and ls to find the files but keep getting errors.
Thanks in advance
fid = fopen('OneDrive/MATLAB/ar_work/ar_index_realtime_SO.txt');
fullfile_root = textscan(fid,'%s');
fclose(fid);
prof_index = fullfile_root{1};
all_profs = ls(prof_index);
num_files=length(all_profs);
prof_vars = {'LATITUDE','LONGITUDE','JULD','REFERENCE_DATE_TIME','PRES','PRES_QC','TEMP','TEMP_QC','PSAL','PSAL_QC','N_PROFS'};
LAT = cell(num_files,1);
LON = cell(num_files,1);
T_REF = cell(num_files,1);
JULD = cell(num_files,1);
PRES = cell(num_files,1);
PRES_QC = cell(num_files,1);
TEMP = cell(num_files,1);
TEMP_QC = cell(num_files,1);
PSAL = cell(num_files,1);
PSAL_QC = cell(num_files,1);
for K = 1 : num_files
LAT{K} = ncread(all_profs, prof_vars{1}); % etc
end
2 commentaires
Guillaume
le 29 Mai 2019
Modifié(e) : Guillaume
le 29 Mai 2019
An example ar_index_realtime_SO.txt file would help us understand your code better. Comments wouldn't hurt either.
Although, considering that prof_index is always going to be a cell array of char vectors, I don't see how ls(prof_index) or dir(prof_index) could ever work since neither accept cell arrays as inputs. Plus if, your file has more than one line, it's really not clear what the ls intent is (get the listing of each directory?).
Réponses (0)
Voir également
Catégories
En savoir plus sur Large Files and Big Data 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!