6
$\begingroup$

I have a list abc={{{x1,y1},{x2,y2},{x3,y3}}}, where all the x and y are the coordinates.

How to import the coordinates into a text file, in which each line only has one pair of coordinates? Ideally, I want the x and y coordinates separated by a space, but without any brackets or comma.

I tried using the Export['testing.txt', abc], but it ends up with lots of brackets, comma, and all in one line. They are also in scientific notation e.g. {1.6438124245508942*^-9, 4.264146107953855*^-9}. I want them to be plain decimal numbers.

thanks

$\endgroup$
9
$\begingroup$

I am not sure of the best way but here is one method.

As I understand it you don't want scientific notation.

abc = RandomReal[{0, 1}, {3, 2}]*10^-9

Convert the list to strings after applying AccountingForm.

strings = Map[{ToString[AccountingForm[#[[1]]]], 
    ToString[AccountingForm[#[[2]]]]} &, abc]

It looks like

Grid[strings]

Mathematica graphics

Export strings using "Table"

Export["strings.txt", strings, "Table"]
$\endgroup$

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.