I have 1000 text files that their names are A0000.txt, A0001.text, ..., A1000.text. I want to read in the information in the text files and store some of them in an excel file or a csv file (csv is preferred).
How should I define a for loop that can do this task?
I can use this function A = textread('A0000.txt','%s')
to read one text file, but I don't know how should I put it in a for loop. If the name of the files were 1.txt, 2.txt,..., 1000.txt it would be easier.
I would be thankful if you can provide any help.
You should use sprintf
to generate the relevant strings:
for i=1:1000
fileName = sprintf('A%04d.txt',i);
A{i} = textread(fileName ,'%s')
end
The %04d
tells sprintf
that the number should have leading zeroes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With