Search code examples
matlabfilecomplex-numberstextscan

Matlab: using textscan to read complex numbers


I have a text file cTest.dat with a bunch of complex numbers in the following format:

(2.324,2432) (-1.24,-3.43) 
(2.4,0) (1.24,-8.85) 
(-2.324,4.56) (-1.24,-3.43) 

and I'd like to read them into matlab. From the help site it seems textscan would be a good choice and I try

id2=fopen('cTest.dat');
C = textscan(id2, '(%f , %f)');

However this gives me

C = [6x1 double]    [6x1 double]

Does anyone know how to do this?


Solution

  • You just need one more line:

    C=complex(C{1,1},C{1,2})