How to import a txt file number by number?

조회 수: 1 (최근 30일)
Zulkuf Azizoglu
Zulkuf Azizoglu 2020년 11월 6일
편집: Stephen23 2020년 11월 9일
Hey,
I have a txt file with 100 rows and 100 columns of zeros and ones.
Txt file looks like: (There is a space between each rows)
10100101000101...
01010001010100...
I want to read each row number by number, and then move onto reading the next row. Finally, I would have an array (either 1 dimentional or 2 dimentional) with 10000 numbers. How can I do this?
Thank you!
  댓글 수: 1
dpb
dpb 2020년 11월 6일
"I want to read each row number by number, and then move onto reading the next row. "
Why?
Just read the file and process it sequentially if desired -- there's nothing to be gained by reading piecemeal.

댓글을 달려면 로그인하십시오.

답변 (1개)

Pranav Verma
Pranav Verma 2020년 11월 9일
Hi Zulkuf,
From what I understand from your query is that you want to read all the numbers (which are in text form) from the txt file in an array.
You can try the fscanf method to accomplish the same.
You may also refer to the below discussion thread on the similar lines:
Thanks
  댓글 수: 1
Stephen23
Stephen23 2020년 11월 9일
편집: Stephen23 2020년 11월 9일
Tip: format '%1d' does it quite nicely.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by