read binary file into matrix

36 ビュー (過去 30 日間)
Duncan
Duncan 2012 年 12 月 4 日
I have a binary file, that is encoded as hex. If I use fread on it I get a 8192x1 double with values like these:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 69 48 48 50 50 69 55 50 54 57 09
these are hex values, so 69 is E for example. Now at the end there is an 09 (tab) and I would like that tab to indicate to go to the next cell in a matrix, so that when I read and process the file, I have all the data stored in a matrix. Now if this were a tab-indented file, I would just use importdata(...), but as it is in a binary, that I have to convert to a string, and then to a matrix, I can't figure out how to do it. Any ideas?

回答 (1 件)

Muthu Annamalai
Muthu Annamalai 2012 年 12 月 4 日
編集済み: Muthu Annamalai 2012 年 12 月 4 日
Pay attention to the 'source' and 'precision' options to fread().
>> doc fread
is your friend
% Create the file
fid = fopen('magic5.bin', 'w');
fwrite(fid, magic(5));
fclose(fid);
% Read the contents back into an array
fid = fopen('magic5.bin');
m5 = fread(fid, [5, 5], '*uint8');
fclose(fid);

カテゴリ

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