Read all text files in folder (nonsequential)
Afficher commentaires plus anciens
I need matlab to read all text files within a folder. The number typically are sequential; however, the limitation of the existing MATLAB script is that it doesn’t allow for non-consecutive numbered tests, beginning only at xxxx001.dat to be processed. I would like all .dat files contained within a specific folder to be processed at the same time.
RT_number=1917; t1start=tic; warning off MATLAB:xlswrite:AddSheet;
for i=1:999 tic; if i>=1 && i<=9
zero='00';
end
if i>=10 && i<=99
zero='0';
end
if i>=100 && i<=999
zero='';
end
filename=[int2str(RT_number) zero int2str(i) '.dat'];
end
fid=fopen(filename);
Réponse acceptée
Plus de réponses (1)
Mahdi
le 23 Mai 2014
Based on what you said, if you have all the files in the same folder, you can open the folder in MATLAB and use dir to list all the folder contents (With other options if you want, or even tell dir which folder to list the contents for). Similarly, you can use ls.
You can then use a loop to open up these files, for example (assuming you're in the folder already)
filelist=ls;
[m, n] size(filelist);
for i=1:m
fid=fopen(filename(i,1:end))
end
You can do the same thing dir, but you would need to use filelist(i).name
1 commentaire
Russell
le 23 Mai 2014
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!