How to read input.txt?
古いコメントを表示
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 件のコメント
KSSV
2021 年 8 月 24 日
First two lines are strings...how you can read them as integer?
Yasuyuki Hamanaka
2021 年 8 月 24 日
Stephen23
2021 年 8 月 24 日
@Yasuyuki Hamanaka: what integer do you expect the characters 'aaaaaa' to return ?
採用された回答
その他の回答 (1 件)
dpb
2021 年 8 月 24 日
0 投票
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
カテゴリ
ヘルプ センター および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!