I have a file, listOfResults.txt, consisting of many rows of which the following is an example:


What is a good choice for Export parameters when importing numbers like those shown, including the scientific type?

First three numbers in each row are parameters, the remaining numbers are results.

I would like to import it to a variable rawData as a table of numbers or test (I don't know what to choose). Then I want to convert the scientific forms such as 2.Te+6 to a form understood by Mathematica.

I also want to write code for a function listOfResults such that

listOfResults[0.074, 0.004, 1000]


{3.29561*10^9, 0.001, 3.27917*10^9}


Import-data does not allow me use the scientific conversion:

rawData = StringReplace[rawData, {"e+" :> "*^", "e-" :> "*^-"}]

Import-string allows use the above code, but it is problematic to instruct the function listOfResults to the call

listOfResults[a, b, c]

work correctly with the parameters a, b, c — the c parameter works for 1.0*10^3 but not for 1*10^3.

I have tried

rawData = Import[file, "Data"]

rawData = StringReplace[rawData, {"e+" :> "*^", "e-" :> "*^-"}]

rawData = ImportString[rawData, "CSV"];

(listOfResults[rawData[[#, 1]], rawData[[#, 2]], rawData[[#, 3]]] = 
   {{rawData[[#, 4]]}, Drop[rawData[[#]], 4]}) &
  • 1
    $\begingroup$ Import[ file, "CSV" ] ? $\endgroup$ – LouisB Aug 9 '18 at 21:17
  • $\begingroup$ There may be something strange going on with this string because when I copy it into Mathematica is does not look like it does here on Stack Exchange (double commas, among other things) but when corrected it works with ImportString[str, "CSV"] (i.e. you don't have to do replacements and such.) As LouisB says, Import[file, "CSV"] should work. $\endgroup$ – C. E. Aug 10 '18 at 12:13
  • $\begingroup$ I have simplified it but the original .nb file adjusted now based on LouisB's comment with the result file is here: drive.google.com/file/d/1B5l2icboZhU7s1PZ_NiSdDUbWlRYWW6t/… unfortunately still not working, the last input does not provide the results $\endgroup$ – Karel Aug 10 '18 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.