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!