How to read input.txt?
Show older comments
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 Comments
KSSV
on 24 Aug 2021
First two lines are strings...how you can read them as integer?
Yasuyuki Hamanaka
on 24 Aug 2021
Stephen23
on 24 Aug 2021
@Yasuyuki Hamanaka: what integer do you expect the characters 'aaaaaa' to return ?
Accepted Answer
More Answers (1)
dpb
on 24 Aug 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
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!