How to read input.txt?
Mostrar comentarios más antiguos
Hello!
Would you tell me how to read .txt file like below.
aaaaaa
bbbbbb
1
200
2000
4129
4189
I would like to read first two lines as string and other lines as real.
I tried to use fscanf though, it doesn't work well.
Thank you.
3 comentarios
KSSV
el 24 de Ag. de 2021
First two lines are strings...how you can read them as integer?
Yasuyuki Hamanaka
el 24 de Ag. de 2021
Stephen23
el 24 de Ag. de 2021
@Yasuyuki Hamanaka: what integer do you expect the characters 'aaaaaa' to return ?
Respuesta aceptada
Más respuestas (1)
dpb
el 24 de Ag. de 2021
0 votos
Are the string data pertinent or just in the way of returning the numeric data?
If the former, while you can make it work with low-level i/o such as fprintf, it's the hard way to go at it -- use
readcell instead.
If the latter and the text is (say) a header line and units or similar, use readtable
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!