How to process .txt files in a folder to be read by readtable?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
KSSV
le 11 Juil 2019
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
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!