How to process multiple txt files in a loop?
Show older comments
I have multiple txt files in a folder, and I wrote a code to process a single file:
function output = do(input)
filename = ('c:\.....');
fileID = fopen(filename);
.....
process data
.....
output single output
fclose(fileID);
end
What is needed so that MATLAB processes all the files in the folder, and output all output into a single column matrix?
Much Thanks!
Accepted Answer
More Answers (1)
Massimo Zanetti
on 27 Sep 2016
Edited: Massimo Zanetti
on 27 Sep 2016
With DIR function you have access to all data in a folder. An example is
%provide the path to your folder as argument
MyFolderInfo = dir('C/...');
%the names of the files are:
%MyfolderInfo(1).name
%MyfolderInfo(2).name
%etc....
%for example you can run your function DO on each of them
for k=1:size(MyFolderInfo,1)
out{k} = do(MyFolderInfo(k).name);
end
Categories
Find more on File Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!