0

I've got a list of data with the following structure

A snapshot of the data imported with matematica

which can be easily converted To expresion by some manipulation such as

StringSplit[ToString[data], {"  ", "\n"}];

StringSplit[ToString[data[[1]]], {" ", "\n"}];

and I get the list i am interested on and its output:

mx = Table[ToExpression[data[[2 + 8*i]] ], {i, 1,Length[data]/8 - 1}];

0.0158183, 0.0158061, 0.0157933, 0.0157796, 0.0157652, 0.0157499, \ 0.0157337, 0.0157165, 0.0156982, 0.0156788, 0.015658, 0.0156358, \ 0.015612, 0.0155863, 0.0155583, 0.0156255 + 0.999848 (-5 - 9.80429 e), 0.0155807 + 0.999848 (-5 - 8.85353 e), 0.0155284 + 0.999848 (-5 - 7.88611 e), 0.015463 + 0.999848 (-5 - 6.90164 e), 0.0153814 + 0.999848 (-5 - 5.91632 e), 0.0152822 + 0.999848 (-5 - 4.94252 e), 0.0151678 + 0.999848 (-5 - 3.98449 e), 0.0150438 + 0.999848 (-5 - 3.04207 e), 0.0149143 + 0.999848 (-5 - 2.11355 e), 0.0147807 + 0.999848 (-5 - 1.19662 e), 0.0146437 + 0.999848 (-6 - 2.90415 e), 0.0145031 + 0.999848 (-6 + 6.0634 e), 0.0143595 + 0.999848 (-5 + 1.49482 e), 0.0142126 + 0.999848 (-5 + 2.37426 e), 0.0140625 + 0.999848 (-5 + 3.24488 e), 0.0139089 + 0.999848 (-5 + 4.1055 e), 0.0137518 + 0.999848 (-5 + 4.95496 e), 0.0135908 + 0.999848 (-5 + 5.78955 e), 0.0134258 + 0.999848 (-5 + 6.60316 e), 0.0132566 + 0.999848 (-5 + 7.39248 e), 0.0130828 + 0.999848 (-5 + 8.13654 e), 0.0129038 + 0.999848 (-5 + 8.72386 e), 0.0127163 + 0.999848 (-5 + 8.76224 e), 0.0125254 + 0.999848 (-5 + 9.86248 e), 0.0124538, 0.0113728, 0.0104582 + 0.999848 (-5 + 8.81941 e), 0.00985979 + 0.999848 (-6 - 3.81614 e), 0.00938305 + 0.999848 (-5 - 6.02078 e), 0.00894878 + 0.999848 (-5 - 8.67399 e), 0.00759501 + 0.999848 (-5 + 5.43005 e), -0.0157732, -0.0157874, -0.0158007, -0.0158133, \ -0.0158251

As you can see the data is not properly converted . Is there some easy way for a beginner to avoid this problem ?

halirutan
  • 112,764
  • 7
  • 263
  • 474
J. Angel
  • 3
  • 3
  • By the way, The original data file It is a .txt that can be easily plotted with gnuplot but that's not what I am looking for. – J. Angel Aug 31 '15 at 10:13
  • 1
    Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Aug 31 '15 at 10:17
  • 1
    There's something funny about the way your question is formatted. Can you clean it up a bit to make it more readable? You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful – Michael E2 Aug 31 '15 at 10:19
  • 1
    SemanticImportString might solve your parsing problem. – Stephen Luttrell Aug 31 '15 at 10:34
  • You can write a newline as "\n" in Mathematica. I edited this in your post for clarity. Please check that it's still what you meant to use. – Szabolcs Aug 31 '15 at 10:41
  • 1
    I don't see the problem. I downloaded it and the following works fine for me: data = Import["test.txt", "Table"]; Please include details on how you import the file... Drop[data,1] to remove headers. – V.E. Aug 31 '15 at 10:48
  • possible dup http://mathematica.stackexchange.com/q/1737/2079 – george2079 Aug 31 '15 at 11:51
  • 1
    I'm voting to close this question as off-topic because the problem cannot be reproduced. Using Import[table.txt, "Table"] on your data works just fine. – MarcoB Aug 31 '15 at 15:38

1 Answers1

2

I have uploaded your table.txt to a code sharing server. This is exactly like the data should look on your disk.

As already mentioned in several comments, you just have to import it as "Table" and everything is fine:

data = Import["http://hastebin.com/raw/cudesisezu", "Table"];
data[[2]]

(* {0, 0.997046, -4.00611*10^-6, -0.00442103, 0.299956, 0, -0.00523568,
  0} *)
halirutan
  • 112,764
  • 7
  • 263
  • 474
  • You're right. The flag "Table" seems to solve the problem. Another way is to use the undocumented mathematica function Internal`StringToDouble[s] as george2079 suggested. Thanks to everyone for your useful comments and answers. – J. Angel Sep 02 '15 at 08:49