필터 지우기
필터 지우기

What is the difference between fopen( 'r'),fopen('r','b') ?

조회 수: 31 (최근 30일)
subha
subha 2014년 6월 30일
댓글: subha 2014년 7월 3일
When i try to open a file in different way, i get different ans. what it represent? As per my understanding from documents, 'b' represent machine format. b represets bigendian format. By default it will take little indian format. so second one takes little endian format. When i go through about big and little indian, it is memory representation format. what is the difference between the values in 1 and 2.
1. fid = fopen('train-images-idx3-ubyte', 'r', 'b')
header = fread(fid, 1, 'int32')
header =
2051
2. fid = fopen('train-images-idx3-ubyte', 'r')
header = fread(fid, 1, 'int32')
header =
50855936
  댓글 수: 1
Philip Borghesani
Philip Borghesani 2014년 7월 1일
Just be careful 'rb' in MATLAB is not the same as 'rb' in C. In C on Windows b means binary mode which is the default in MATLAB, to get text mode fopen (the default in C on Windows) use rt in MATLAB.
C has no equivalent to the machine format options in MATLAB.

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

채택된 답변

dpb
dpb 2014년 6월 30일
편집: dpb 2014년 7월 1일
Storage order in memory of which byte in memory is the most/least significant. See the following link for details...
ADDENDUM
That, of course, is for the syntax of your case 1) which, I now note is NOT the same as that of the subject line of the question;, ie,
fid=fopen(filename,'r','b');
is nothing at all like
fid=fopen(filename,'rb');
--the two 'b' 's are entirely different animals owing to position. In the former, it's the optional third argument in the syntax
[FID, MESSAGE] = fopen(FILENAME,PERMISSION,MACHINEFORMAT);
so it's the MACHINEFORMAT parameter, in the latter it's the second (also optional) argument as in
[FID, MESSAGE] = fopen(FILENAME,PERMISSION)
so it's part of the PERMISSIONs string in which case it is, as Philip notes, indicating a stream ('binary') file format as opposed to ASCII ('text') as given by the 't' substring.
Again, see
doc fopen
and read all the supplementary description for the various parameters for the details. The short story is that the 't' indicates text mode that forces the cr/lf pair for \n on Windows that is superfluous in Unix-like OS platforms.

추가 답변 (0개)

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by