How do I open the only text file in the directory without mentioning the name in my MATLAB code?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SRIHARSHA SUSARLA
el 11 de Jul. de 2014
Comentada: Star Strider
el 11 de Jul. de 2014
I have a text file that has some string data which is to be imported into the MATLAB program. For this, how would I read it directly, without having to mention it's name every time, because it's in the same directory.
0 comentarios
Respuesta aceptada
Star Strider
el 11 de Jul. de 2014
You have to mention its name in some respect, so that the operating system will know what file to open. It’s easy to get the name in your script automatically:
txtfile = dir('*.txt');
filename = txtfile.name;
After that, open and read it however you like. It would be easiest if you saved it as a ‘.mat’ file (that could be saved in ASCII format), because you could then simply use the load function and not have to bother with the format. See the documentation on save and load for details.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Search Path 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!