# Import complex numbers from a CSV file created in MATLAB

I export a simple CSV file created in MATLAB with complex numbers, such as:

0.1+2.1i,0.9+0.13i,0.02+0.3i

I would like to import it into Mathematica with the "i" recognized as the imaginary unit, of course. Unfortunately, a simple Import["filename"] command does not work, and neither does Import["filename","CSV"]. I have also tried the solution method proposed here, but unfortunately without success.

How can I do it?

PS: Following Bill's suggestion, here is the output from InputForm:

{{"0.1+2.1i", "0.9+0.13i", "0.02+0.3i"}}

• Please edit your post to include the result of InputForm[Import["filename"]] and put that on a single line by itself with four spaces in front of it so Stackexchange will understand that line is code and to do less "desktop publishing" on it before we get to see it. That will hopefully show people here exactly what Mathematica is getting from your file import and then people can try writing a line of code to fix it for you
– Bill
Jun 2 at 14:07

 lis = {"0.1+2.1i", "0.9+0.13i", "0.02+0.3i"};
new = StringReplace[#, "i" -> "*I"] & /@ lis
new = ToExpression[new] You can apply the above to your input, depending on what you used to import the Matlab file.

As an appendix (not official answer), if you have access to the new Wolfram language LLMFunction you can also try

lis={"0.1+2.1i","0.9+0.13i","0.02+0.3i"};
LLMFunction["please convert these from Matlab to Mathematica . Thank you."][lis];
ToExpression[%]

(* {0.1 + 2.1 I, 0.9 + 0.13 I, 0.02 + 0.3 I} *)


Screen shot on V 13.2.1 • Thanks! That worked! Jun 2 at 15:18

Alternatively,

lis = {"0.1+2.1i", "0.9+0.13i", "0.02+0.3i"};

SemanticInterpretation /@ lis

(* {0.1 + 2.1 I, 0.9 + 0.13 I, 0.02 + 0.3 I} *)