how to read specific columns from several data files stored in a folder.

조회 수: 8 (최근 30일)
MA
MA 2021년 9월 20일
댓글: MA 2021년 9월 20일
assuming we have a folder that has several data files inside it and the data files are in row/column format, how we can read or extract only specified columns of each file, process them as we need and then move to the next file and so on, rather than reading the whole files.
currently I am using the following code, but it reads the whole file, for effeciency purposes how I can modify this to make the table 't' consists of columns of my choice and not having to read the whole file? or is there a better way to do that?
filePattern = fullfile(myFolder, '*.*');
theFiles = dir(filePattern);
theFiles = theFiles(~[theFiles.isdir]); %remove folders from list
nfiles = length(theFiles);
fullnames = fullfile({theFiles.folder}, {theFiles.name});
results(:,1) = fullnames(:);
for k = 1 : nfiles
fullFileName = fullnames{k};
t = readtable(fullFileName);
end
  댓글 수: 2
Stephen23
Stephen23 2021년 9월 20일
"...how I can modify this to make the table 't' consists of columns of my choice and not having to read the whole file?"
Did you read the READTABLE documentation?
Or the documentation for READMATRIX or DLMREAD or any other function that you might use to import your file data?
MA
MA 2021년 9월 20일
thanks for the advice, I just checked the READTABLE documentation and sorted it out. thank you!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by