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 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