Effacer les filtres
Effacer les filtres

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

31 vues (au cours des 30 derniers jours)
subha
subha le 30 Juin 2014
Commenté : subha le 3 Juil 2014
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 commentaire
Philip Borghesani
Philip Borghesani le 1 Juil 2014
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.

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 30 Juin 2014
Modifié(e) : dpb le 1 Juil 2014
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.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by