How to read many arbitrary text files in MATLAB?
Show older comments
Dear everyone,
Please help me to solve this problem. I need to make a code that can read data from a text file for example ClCdCm.txt. If there is only one file, it can be read easily by the following code:
ClCd = fopen('ClCdCm.txt') % Read Cl, Cd and Cm data
C2_text = textscan(ClCd,'%s',4);
C2_data = textscan(ClCd, '%f %f %f %f');
However, now I have many text files for example ClCdCm1.txt , ClCdCm2.txt , ClCdCm3.txt ,... These files are generated by another program and we do not know how many file there will be. There can be one file, two files, ten files or whatever. But the files are named with a rule as above. Can anyone help me to write a code to manage and read these files?
Thank you so much!
Accepted Answer
More Answers (1)
Sara
on 24 Jul 2014
k = 1;
while exist(['ClCdCm',num2str(k),'.txt'],'file')
%insert code to read file
k = k + 1;
end
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!