how to read binary data from text file ? is there a way to convert this read data in signed integer?

22 views (last 30 days)
I attached a text file in which contains the binary values. All binary values are 32bits size & text file contain 1 column with each row as 1 binary value. It will be good if i got those value in single column in matlab too. Also, Is there a way to convert this binary data in signed decimal in matlab.
waiting for someone to help me with this.

Accepted Answer

Guillaume
Guillaume on 26 Jul 2018
There are two lines with 'xxxx', what do you want to do with them?
The last line does not have 32 bits, how is that to be interpreted?
For now, I just delete them:
text = strsplit(fileread('vivado_output_arctan.txt'), {'\r', '\n'}); %read file and split into lines
isvalid = ~cellfun(@(t) any(t == 'x') | numel(t) < 32, text); %line scontaining 'x' or shorter than 32 bits are not valid
unsigned = bin2dec(text(isvalid)); %convert valid lines from binary to decimal. bin2dec always assume unsigned
signed = typecast(uint32(unsigned), 'int32') %convert from unsigned to signed

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!