Importing multiple text files from multiple folders
Ältere Kommentare anzeigen
I wrote the following code to read the files I need.
runs = 33137;
folders = 22;
format = '%f%C%C';
filestop = folders;
for N = 1:filestop
for n = 1:runs
foldstr = num2str(N);
indstr = num2str(n);
filename = strcat('C:\PERALS_Ra-226\b',foldstr,'\Sample226Ra(',indstr,').txt');
T = readtable(filename,'Delimiter',',','Format',format,'ReadVariableNames',false);
col = n;
A(:,col) = table2array(T(:,1:1));
fileID = fopen(filename);
tline = fgetl(fileID);
grabd = textscan(tline,'%*f%*s%{M/d/yyyy h:mm:ss a}D','delimiter',',');
stopdate(1,col) = datetime(grabd{1,1});
for M = 1:15
tline = fgetl(fileID);
end
grab = textscan(tline,'%*f%*s%d','delimiter',',');
rt(1,col) = grab{1,1};
for O = 1:15
tline = fgetl(fileID);
end
grab = textscan(tline,'%*f%*s%f','delimiter',',');
dt(1,col) = grab{1,1};
fclose(fileID);
end
end
The problem with my code is that there are a total of 33137 text files, however each folder does not have that many files. How can I change this code to read all of the files I need?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Low-Level File I/O finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!