can anybody help in understanding fopen and fread?

18 vues (au cours des 30 derniers jours)
subha
subha le 20 Juin 2014
Commenté : subha le 30 Juin 2014
As per my understanding, fopen open the file in a mode which we want. For example, if we say r,then it opens in read mode. fread, read the open file and returns the no of elements.
Based on above line, i tried below code.
f= fopen('train-images-idx3-ubyte', 'r')
Ans:
f =
56
Here what 56 represents? I understand it is file identifier. How it is generated?
[a, count]= fread(f,4,'int 32')
a =
1.0e+09 *
0.0509
1.6259
0.4698
0.4698
count =
4
Could anybody help me to understand the above result.

Réponse acceptée

Image Analyst
Image Analyst le 20 Juin 2014
f is some identification number of the file. Don't worry about what it's actual value is or how it's generated - it doesn't matter (as long as it's not -1 which indicates an error). It's simply used to tell fread() or fprintf() what file to talk to.
The fread line read four 4-byte integers from the binary file. You store them into variable "a". It should be 'int32' rather than 'int 32' though.
  11 commentaires
Image Analyst
Image Analyst le 30 Juin 2014
Did you try Google? Lots of readers for it there: https://www.google.com/?gws_rd=ssl#newwindow=1&q=mnist+matlab+code&safe=off
subha
subha le 30 Juin 2014
Thanks a lot. it really helps me..

Connectez-vous pour commenter.

Plus de réponses (1)

Marta Salas
Marta Salas le 20 Juin 2014
The file identifier is a integer greater than 3. Identifier -1 means fopen can not open the file, and MATLAB reserves file identifiers 0, 1, and 2 for standard input, standard output (the screen), and standard error, respectively.
[a, count]= fread(f,4,'int 32')
This line is reading 4 values in the file f such that the source data is class uint32. Then the 4 values are stored in a and the number of values read from the file is stored in count

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by