How to import a txt file number by number?

1 Ansicht (letzte 30 Tage)
Zulkuf Azizoglu
Zulkuf Azizoglu am 6 Nov. 2020
Bearbeitet: Stephen23 am 9 Nov. 2020
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 Kommentar
dpb
dpb am 6 Nov. 2020
"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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pranav Verma
Pranav Verma am 9 Nov. 2020
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 Kommentar
Stephen23
Stephen23 am 9 Nov. 2020
Bearbeitet: Stephen23 am 9 Nov. 2020
Tip: format '%1d' does it quite nicely.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by