# Data manipulation in Mathematica

I have a very big data set that I have generated in Matlab. I am importing into Mathematica since doing some data manipulation is much easier.

There is one caveat, which is the following: I have some data entries that appear as the string

"0.677 + 9.121e-12i"


or

"1.247e-12 + 0.182i"


where e-12 is actually the exponential of -12 (i.e. very small). Due to the formatting of the exponential, Mathematica does not recognise it as an exponential. Hence, I want to set any term that contains e to be 0 such that for the two entries above, I get:

"0.677"
"0.182i"


I am then able to use ToExpression to recast the whole data set to something that I can further manipulate.

You can use the following operator:

op = ToExpression@*StringReplace[{"e+" -> "*^", "e-" -> "*^-", "i" -> "I"}]


which can then be applied to strings of numbers:

op["0.677 + 9.121e-12i"]
op["1.247e-12 + 0.182i"]

• Can this be applied to a matrix of strings? – Sid Nov 15 '19 at 16:53
• i.e. currently, I have to apply it recursively on each element of the matrix. Any better way to do this? – Sid Nov 15 '19 at 16:55
• @Sid, try Map[op, mat, {2}] – J. M.'s technical difficulties Nov 15 '19 at 17:00
• I would throw a Chop in op to get rid of the small terms and produce the wanted results. – NonDairyNeutrino Nov 15 '19 at 22:46