Read hex data from txt file and convert to signed integer

Dear members, I have a text file that has 10 bit singed hexadecimal numbers. I want to convert it to signed integers. I am attaching the text file for testing as well. Thanks in advance.

 採用された回答

Usman Ashraf
Usman Ashraf 2018 年 2 月 4 日

2 投票

I just figured out the answer myself and am sharing here for others.
filename = 'Filter_Output.txt';
q = quantizer('fixed', 'nearest', 'saturate', [10 0]);% quantizer object for num2hex function
FID = fopen(filename);
dataFromfile = textscan(FID, '%s');% %s for reading string values (hexadecimal numbers)
dataFromfile = dataFromfile{1};
decData = hex2num(q, dataFromfile);
decData = cell2mat(decData);
fclose(FID);

2 件のコメント

Glen Miskimins
Glen Miskimins 2018 年 11 月 3 日
Thanks Usman! I needed to do the same thing!
Usman Ashraf
Usman Ashraf 2018 年 11 月 3 日
Glad to know it helped :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by