Why are some bytes skipped from input when I try to use FREAD function to read a file that is opened in 'rt' mode on Windows platforms in MATLAB 7.11 (R2010b)?

2 Ansichten (letzte 30 Tage)
I am trying to read the contents of a binary file one byte at a time using the FREAD function. I use the following commands to open a file and then perform the read operation.
fid = fopen('myFile.dat','rt')
while ~feof(fid)
data = fread(fid,8,'uint8');
dec2hex(data)
end
fclose(fid)
Upon execution, I observe that where ever there is an input sequence 0D(in hex) followed by 0A(in hex) in the source file, the byte for '0D' is ignored in the read input.
I expect to get the data into MATLAB exactly as it is in the input file.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 7 Okt. 2010
This behavior is observed on Windows platforms when you read a file in text mode using the 'rt' option in FOPEN. The following applies on Windows systems, in text mode:
- Read operations that encounter a carriage return followed by a newline character ('\r\n' or 0D 0A in Hex) remove the carriage return from the input.
- Write operations insert a carriage return before any newline character in the output.
Please refer to the documentation of FOPEN function for more information:
<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fopen.html>

Weitere Antworten (0)

Kategorien

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

Produkte


Version

R2010b

Community Treasure Hunt

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

Start Hunting!

Translated by