How to read input.txt?
Afficher commentaires plus anciens
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 commentaires
KSSV
le 24 Août 2021
First two lines are strings...how you can read them as integer?
Yasuyuki Hamanaka
le 24 Août 2021
Stephen23
le 24 Août 2021
@Yasuyuki Hamanaka: what integer do you expect the characters 'aaaaaa' to return ?
Réponse acceptée
Plus de réponses (1)
dpb
le 24 Août 2021
0 votes
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
Catégories
En savoir plus sur Text Data Preparation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!