I'm working on a project of Nuclear physics and I'm passing results of a simulation program to mathematica via a txt file. I then read the values I need to read and plot them. The problem is that sometimes those values don't appear on the file, and then mathematica gets an "end of file" error instead of a value when I try to find them. Everything works fine with the plot, but if I want to show the results on a table it's all messed up and filled with errors.


How do I remove all the errors from a list like this:


replacing them with zeros?

I want to get something like this:


Thanks and sorry for the messy question.

  • $\begingroup$ (at) DoubleCat: It seems as if the value 0 is misinterpreted as an EOF marker. Try writing 0.0 instead of 0 in your text file. $\endgroup$ – Dr. Wolfgang Hintze Sep 21 '14 at 17:30
  • $\begingroup$ That is what I want to get, I don't know how to do it $\endgroup$ – DoubleCat Sep 21 '14 at 17:33
  • $\begingroup$ To try it, take a small txt file, replace an exact 0 by 0.0 e.g. by hand, and then pass this file to Mathematica. Do the error messages remain? If not, then you should adapt your text generation to include just this replacement. If yes, I don't know ... $\endgroup$ – Dr. Wolfgang Hintze Sep 21 '14 at 17:37
  • $\begingroup$ Replace[YourList, x_ /; Not@NumericQ@x :> 0, {2}] $\endgroup$ – Dr. belisarius Sep 21 '14 at 17:41
data /. Internal`StringToDouble[__] -> 0

{{40., 0}, {45.45, 0}, {50.91, 49.5}, {56.36, 78.9}, {61.82, 70.9}, {67.27, 32.6}, {72.73, 9.4}, {78.18, 3.9}, {83.64, 1.1}, {89.09, 0.2}, {94.55, 0.1}, {100., 0}}

  • $\begingroup$ Thank you so much, you saved me $\endgroup$ – DoubleCat Sep 21 '14 at 18:07
  • $\begingroup$ My pleasure @ 2Cat $\endgroup$ – eldo Sep 21 '14 at 18:11

Your Answer

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

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