how to open multiple .txt files?

2 Ansichten (letzte 30 Tage)
Lilya
Lilya am 20 Dez. 2020
Beantwortet: Ive J am 20 Dez. 2020
Hi all,
I have certin number of txt files with different names (ex: 5, 10, 15, 20, 25, 30, 35, 40, 80, 120, ...)
I want to open them using a loop.
Any help would be appreciated.

Akzeptierte Antwort

Ive J
Ive J am 20 Dez. 2020
If all the files have the same structure/data format, you can use datastore to merge them:
fileNames = {'t1.txt', 't2.txt', 't3.txt'}
ds = readall(datastore(fileNames)); % change other properties if needed
otherwise, you can use readtable within a loop
fileContents = {};
fileNames = {'t1.txt', 't2.txt'};
for i = 1:numel(fileNames)
fileContents{i, 1} = readtable(fileNames{i});
end

Weitere Antworten (0)

Kategorien

Mehr zu Text Data Preparation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by