フィルターのクリア

how to read .bin file?

119 ビュー (過去 30 日間)
RAJKUMAR Palaniappan
RAJKUMAR Palaniappan 2013 年 6 月 14 日
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 Center および File ExchangeLarge 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