How to process .txt files in a folder to be read by readtable?
3 ビュー (過去 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!