How to process .txt files in a folder to be read by readtable?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a folder with a large amount of the same type of file in them with data I want to be processed using the same code. Is there a way I can loop through the folder to read each .txt file to have it be read by using readtable()? I would prefer to use readtable() compared to other import methods. The folder of data is already organized how I'd like it.
data = readtable('01048000D.txt', 'Format', '%q %f %f %f %f %f', 'Delimiter', 'unspecified', 'Headerlines' , 0, 'ReadVariableNames', false)
I just need a way for all of the files to be read in this one folder. I would like to just have the loop change what the file name would be, but I don't know how to do this.
댓글 수: 0
답변 (1개)
KSSV
2019년 7월 11일
txtfiles = dir('*.txt') ;
N = length(txtfiles) ;
data = cell(N,1) ;
for i = 1:N
data{i} = readtable(txtfiles(i).name, 'Format', '%q %f %f %f %f %f', 'Delimiter', 'unspecified', 'Headerlines' , 0, 'ReadVariableNames', false) ;
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!