2

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Sid
  • 977
  • 1
  • 6
  • 15

1 Answers1

3

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"]
SHuisman
  • 3,258
  • 8
  • 12