loading .Bin file

7 views (last 30 days)
David
David on 3 Nov 2011
I am trying to load a binary file into a column vector. The binary file consists of 9 header lines then space delimited lines after that. Intermittently, a hexadecimal string is printed instead of a space delimited line. A sample from the data is below:
985 5147 2212
995 5148 2204
€ SX ! ûSource_0 5 5145 2204
15 5091 2223
25 5043 2222
When I view the middle line in a hex editor I get 0x80010000000053... However when I use fopen then fread the zeros become 0x20, which correspond to ASCII "space". This is a problem because in most of the data, 0x20 is correct, however in the middle section of data above, this is not correct. I have included a section of my code below. Note that I first import the data and then convert it to hex. The error does not occur at conversion but rather when I import the data. I know this because dataFile contains ASCII decimal values.
fid = fopen(fname,'rb');
dataFile = fread(fid,inf,'uint8');
hexFile = cell(1);
while index<=length(dataFile(:,1))
hexFile{index,1} = dec2hex(dataFile(index,1),2);
index=index+1;
end
If anyone could please help me import my binary file straight into hex, I would appreciate it. Thanks.

Answers (0)

Community Treasure Hunt

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

Start Hunting!