MATLAB: Read a file contains hexdecimal complex numbers, and convert decimal complex numbers

converthex

Hi All,
I want to read a file contains hexdecimal complex numbers, and convert decimal complex numbers.
Each line has one hexdecimal complex number. I want to read all lines, and conver the decimal complex number (real and imag parts) and store them in an array. I tried textread, textscan, and so on. I also tried to read them as "str" and split them into two part and convert and combine later. However, all of my approaches failed actually. Please help!
<real_imag.txt>
fffd+0000*i
0016+0000*i
0000+ffff*i
.
.
.

Best Answer

data = fileread('real_imag.txt'); % read data in all char
data_hex = regexp(data, '[\d\w]*', 'match'); % divide all into three parts [real, imag, i] with reguler exp
data_dec = hex2dec(data_hex(1:3:end))+hex2dec(data_hex(2:3:end))*i; % data in decimal