필터 지우기
필터 지우기

Read files from filenames stored in cell array

조회 수: 2 (최근 30일)
Rhiannon Jones
Rhiannon Jones 2019년 5월 29일
편집: Guillaume 2019년 5월 29일
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
Walter Roberson
Walter Roberson 2019년 5월 29일
ncread of fullfile(prof_index, all_profs{K})
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에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by