how to read .bin file?
176 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to read a .bin file in matlab
Note that all values are 16-bit signed integers stored in binary format (2 bytes – not human readable ASCII text).
Can anyone help me???
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Juin 2013
fid = fopen('YourFile.bin', 'r');
data = fread(fid, '*int16');
fclose(fid);
You might need to reshape() the data afterwards.
Depending on how the data was produced and what machine you are using to read it, you might find it necessary to swap the bytes in each integer. There is a MATLAB swapbytes() routine, or there is a FEX contribution http://www.mathworks.com/matlabcentral/fileexchange/17661-swapbytes-c-mex-function that is likely to be faster.
Alternately you might want to add the 'ieee-be' or 'ieee-le' option to the fread() call; that should save you from having to swap the bytes yourself, when the routine that produced the .bin file bothered to document the byte order.
Note: in general, .bin files are not 16 bit signed integers. ".bin" is any arbitrarily complicated binary format, and two .bin files produced by the same program will not necessarily be the same internal format.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!