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 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
MathWorks Support Team
2010-10-7
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>
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!