Reading file with variable name
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
PIYUSH MOHANTY
el 2 de Abr. de 2019
Comentada: Stephen23
el 2 de Abr. de 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?
Respuesta aceptada
the cyclist
el 2 de Abr. de 2019
Editada: the cyclist
el 2 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!