フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by