how to read a text file including the end of line

7 views (last 30 days)
Hello,
I have a text file which is generated by a software. The software saves data from hexadecimal to ascii format. So in the text file, there are a lot of end of line ('\n') characters.
When I use fread or fgets, they will ignore these characters, which will cause data lost. How can I read the file without losing anything?
Thank you.

Answers (1)

Star Strider
Star Strider on 11 Feb 2016
The fgetl function will remove the newline '\n' characters. Is that what you want to do?
  3 Comments
chao zhang
chao zhang on 11 Feb 2016
no, I dont want to remove the newline, but I want to read it as a normal character.
The data process is simply like this: data = fread(fid, N); data_bin = dec2bin(data);
I also need to read the newline, so no data will be lost.
Guillaume
Guillaume on 11 Feb 2016
As walter said, the newline is still there:
data - fread(fid, N);
find(data == 10)
will show you the indices of all the newlines.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!