4
$\begingroup$

I have exported a list of 2d coordinates as a List:

Export["F:\\coordinates.dat", coordinates, "List"];

You can access the data here: http://pastebin.com/wFSt9DiD

Now I would like to read the coordinates back with:

coordinates = Import["F:\\coordinates.dat", "List"];

So far this works.

But, when I want to plot the data with ListPlot the plot is empty.

When I try Flatten[coordinates], the coordinates remain unchanged.

It seems that the imported data is imported as a text list.

How can I access the data in the list?

$\endgroup$

1 Answer 1

4
$\begingroup$

The problem is that the imported "List" objects are all strings,

First@Import["http://pastebin.com/raw/wFSt9DiD", "List"]
(* "{1057.9074074074074, 1045.9222222222222}" *)

So you need to apply ToExpression to get them evaluated,

ListPlot[ToExpression /@ 
  Import["http://pastebin.com/raw/wFSt9DiD", "List"]]

enter image description here

I think, if possible, you are better off exporting your data as a "Table", and then you won't run into this problem

Export["test.dat", 
 ToExpression /@ 
  Import["http://pastebin.com/raw/wFSt9DiD", "List"], "Table"]

and the result is here. You can import it without any hassle now:

ListPlot[Import["http://pastebin.com/raw/ieqin04f"]]
$\endgroup$
2
  • $\begingroup$ Thank you, this is the solution. How do I have to export the data correctly, so that I do not need to convert them back with ToExpression? With mx files only a simple Import is sufficient and the data are available. $\endgroup$
    – mrz
    Commented Feb 11, 2016 at 10:46
  • 1
    $\begingroup$ @mrz, see the last part, use "Table" instead of "List", as in Export["temp.dat", data, "Table"]. Or Export["temp.m", data] if you only need to use the data with Mathematica $\endgroup$
    – Jason B.
    Commented Feb 11, 2016 at 10:47

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.