Read files from filenames stored in cell array

2 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2019-5-29
编辑:Guillaume 2019-5-29
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?).

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by