开发者

Import hex-data from a file with matlab

This is a part of my data.

ªU€ÿ       ÿ  dô      @           @›ÿÿ;<  …æ  ³   3m ...

It is saved in a file. When I look at it with a hex-editor I can see the hex-values. How can I read this "hex-data" with matlab?

EDIT: I get this error:

??? Error using ==&开发者_如何学编程gt; hex2dec at 38
Input string found with characters other than 0-9, a-f, or A-F.

with this code:

a = fread(fid,1,'uint32','l'); 
fprintf('%X',a) 
b = hex2dec(a);


hex2dec() expects a hexadecimal number string as input.

>> hex2dec('28')

With your fread statement I suspect that your 'a' variable will be an integer*4 hence the error message, my understanding being that the precision has already converted the hex string to the type you've declared. If you want to pass this value through hex2dec then you'll need to create a string input.

>> hex2dec(num2str(28));

Do you know the format of your binary file? i.e. is the first value of the data an integer*4?

EDIT: added hex output

In response to the comment, as you read the data in, MATLAB is converting the binary data stream into the format you defined. If you want to get the stream of hexadecimal data then the simpliest way is to convert them back into hexadecimal.

a=dec2hex(fread(fid))

'a' will be a list of all the values in hexadecimal format and should match what you see in your hex editor.


q=dec2bin(hex2dec(num2str(p)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜