how to read .bin file?

119 次查看(过去 30 天)
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???

采纳的回答

Walter Roberson
Walter Roberson 2013-6-14
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 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by