1
$\begingroup$

I have some ASCII-data-tables and for some odd reason there are commas(as decimal mark) instead of dots in the last row. Consider for example:

asciidata=2  1.25E-01  -6.7E-04  -1,6E-05 

So when I try to import it to mathematica, I don't get a list with the desired 4 numbers. I tried to use

Import["asciidata","table","NumberPoint" -> ","]

but then the last number in the example would read -1.6E-05 which I can't get to work for further calculations. What is the correct way to do this?

Here is a short part of the data if this helps

1   0.000000E+00    -7.147784E-04   -3,263987E-04   
2   1.250000E-01    -6.705654E-04   -1,659138E-05
3   2.500000E-01    -6.783623E-04   -3,556275E-05
4   3.750000E-01    -6.636996E-04   -4,519190E-05
5   5.000000E-01    -6.662689E-04   -4,363282E-05
6   6.250000E-01    -6.776148E-04   -6,221215E-05
7   7.500000E-01    -6.863516E-04   -7,101356E-05
8   8.750000E-01    -6.236293E-04   -1,531795E-04
9   1.000000E+00    -6.317795E-04   -1,714623E-04
10  1.125000E+00    -7.069558E-04   -1,841985E-04
$\endgroup$
2
  • 2
    $\begingroup$ StringReplace? $\endgroup$
    – yohbs
    Jul 18, 2017 at 3:46
  • 2
    $\begingroup$ Some of your data is being read as strings. Try this: ToExpression@Import["asciidata", "table", "NumberPoint" -> ","] $\endgroup$
    – LouisB
    Jul 18, 2017 at 5:17

1 Answer 1

6
$\begingroup$

This loads the file "asciidata" as text, replaces every comma by a dot and then imports the result as a table.

ImportString[
 StringReplace[Import["asciidata", "Text"], "," -> "."],
 "Table", "NumberPoint" -> "."
 ]
$\endgroup$
2
  • $\begingroup$ thank you so much! didn't know about ImportString… $\endgroup$
    – freddy90
    Jul 18, 2017 at 10:53
  • $\begingroup$ You're welcome! $\endgroup$ Jul 18, 2017 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.