Reading file with variable name
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
PIYUSH MOHANTY
il 2 Apr 2019
Commentato: Stephen23
il 2 Apr 2019
In the folder I have TEXT files named as PPT1.TXT, PPT2.TXT,PPT3.TXT...., PPT16.TXT. I want to read these files and do some operations like, adding one more column and then save to a new location with same name as PPT1.TXT, PPT2.TXT.... I wish to use a variable for naming these files and do the operation on them as I can just change the name of the variable at one place in the code and the code should should be able to read the correct desired file(PPT1.TXT) and write to the file with the desired name(PPT1.TXT).
But if I put the variable name inside '' (apostropes) in textscan and fprintf commands, it throws error.
Can you please help me with this?
Risposta accettata
the cyclist
il 2 Apr 2019
Modificato: the cyclist
il 2 Apr 2019
for n = 1:16
filename = sprintf('PPT%d.TXT',n)
end
That loop creates the filenames you need, with the '%d' in the sprintf command taking the values of n from the loop.
When you use the filename, don't enclose it in quotes. It is already a character array.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!