How to read input.txt?
Ältere Kommentare anzeigen
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 Kommentare
KSSV
am 24 Aug. 2021
First two lines are strings...how you can read them as integer?
Yasuyuki Hamanaka
am 24 Aug. 2021
Stephen23
am 24 Aug. 2021
@Yasuyuki Hamanaka: what integer do you expect the characters 'aaaaaa' to return ?
Akzeptierte Antwort
Weitere Antworten (1)
dpb
am 24 Aug. 2021
0 Stimmen
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
Kategorien
Mehr zu Text Data Preparation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!