MATLAB Answers

0

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

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.

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Guillaume
on 26 Jul 2018
 Accepted Answer

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