2
$\begingroup$

I have 101 files each with a lot of data. from C output. (.out files) I have imported them to Mathematica 9. However, Mathematica reads the data from each file as an element of a table. So I used StringSplit, to split the data and it looks like this

{{{"425060", "0.214235E+07", "0.48", "0.01", "0.39", "0.49", "0.01", 
   "0.38", "1.64", "-1.65", "-2.13", "518"}, {"6650479", 
   "0.934695E+06", "0.48", "0.39", "0.43", "0.49", "0.39", "0.44", 
   "2.20", "-0.72", "0.51", "226"}, {"1248079", "0.153025E+07", 
   "0.04", "0.07", "0.30", "0.04", "0.07", "0.31", "-0.44", "-0.52", 
   "3.36", "370"}, {"4482147", "0.595558E+06", "0.39", "0.26", "0.38",
    "0.39", "0.28", "0.41", "0.95", "2.76", "5.47", "144"}, ......

My problem is with the E+07 etc terms, when I try to convert this entire data to expressions, using ToExpression, Mathematica converts E -> e=2.73 and evaluates the value. I have tried using HoldForm and Hold etc, however I do need those values to weed out a large portion of data. I have looked into ImportString, StringReplace etc options that were posted here, however they were for individual strings and not a list.

$\endgroup$

marked as duplicate by Nasser, RunnyKine, ubpdqn, Öskå, Teake Nutma Oct 10 '14 at 11:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ s = {"425060", "0.214235E+07", "0.48", "0.01", "0.39", "0.49", "0.01", "0.38", "1.64", "-1.65", "-2.13", "518"}; InternalStringToDouble[#] & /@ s`, see mathematica.stackexchange.com/questions/1737/… $\endgroup$ – Nasser Oct 10 '14 at 5:58
  • $\begingroup$ Thanks, I read that post but I was discouraged by the statement " However, if you are trying to convert many such numbers at once, the standard, documented methods (Import, Read, etc.), are likely to represent better approaches. " $\endgroup$ – HuShu Oct 10 '14 at 6:12
4
$\begingroup$

You can use Internal`StringToDouble:

Map[Internal`StringToDouble, {{"425060", "0.214235E+07", "0.48", 
   "0.01", "0.39", "0.49", "0.01", "0.38", "1.64", "-1.65", "-2.13", 
   "518"}, {"6650479", "0.934695E+06", "0.48", "0.39", "0.43", "0.49",
    "0.39", "0.44", "2.20", "-0.72", "0.51", "226"}, {"1248079", 
   "0.153025E+07", "0.04", "0.07", "0.30", "0.04", "0.07", "0.31", 
   "-0.44", "-0.52", "3.36", "370"}, {"4482147", "0.595558E+06", 
   "0.39", "0.26", "0.38", "0.39", "0.28", "0.41", "0.95", "2.76", 
   "5.47", "144"}}, {2}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thank you very much. Is it possible to apply this for a list of matrices? That's because my data is really a list of matrices, and I have about 100 of such matrices. So I tried Table[Map[Internal`StringToDouble, S[[i]], {2}], {i, 1, 100}], where S[[i]] are the matrices. Thanks. $\endgroup$ – HuShu Oct 10 '14 at 6:10
  • $\begingroup$ @NilanjanBanik, no need for that. Just change {2} to {3} in my code but with your list of matrices. $\endgroup$ – RunnyKine Oct 10 '14 at 6:15
  • $\begingroup$ @NilanjanBanik. My pleasure. Welcome to MMA.SE! $\endgroup$ – RunnyKine Oct 10 '14 at 6:41

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