1

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?

jorgen
  • 3,425
  • 4
  • 31
  • 53
  • what is the format of id2? – NKN Mar 28 '14 at 13:36
  • Can you show an example of the output you are expecting? Its a bit unclear to me what you want in the end... – darthbith Mar 28 '14 at 13:37
  • @darthbith In the end I want to end up with complex numbers (in matlab: 2.324+2432i,...). I was hoping that the above would give me two vectors C(1) and C(2) containing the real and imaginary parts respectively so I could construct the complex numbers. – jorgen Mar 28 '14 at 13:48

1 Answers1

3

You just need one more line:

C=complex(C{1,1},C{1,2})
hyamanieu
  • 1,055
  • 9
  • 25
  • I just used exactly your code and I got the same results as you: 2 cells with 6 doubles. By adding this code line, I got an array of 6 complex double numbers. I use matlab2013b. – hyamanieu Mar 28 '14 at 13:51
  • 1
    I don't know what I did wrong in the previous comment, it works for me too now. Sorry about that and thanks a lot! – jorgen Mar 28 '14 at 13:54