1
$\begingroup$

I have generated the following list: http://pastebin.com/vmtRrfcD (updated)

The dimension of the list is Dimensions[list] = {2726, 2, 2}.

I would like to have as output a text file with the following content:

112.47146693521316  527.3909029875797   593.8622181250886   130.21649411431008
113.09867034214366  528.2037457434733   594.549992796427    131.24153580175766
113.62546758104739  528.8421134663341   595.3257360633687   132.28388880585862
114.5290948275862   529.334513546798    596.099662399775    133.13342242228157
115.71810769492102  529.4806352981145   596.9433184704769   133.62363194162947
116.61911739355284  528.987502154801    597.4328682170543   134.09286821705427
117.53565962656872  527.8425160697888   597.7618282039504   134.43354769560563
118.62483953786906  527.0335365853658   597.9671970965941   134.98297040759348
...

How can that be done?

I tried this:

Export["list.dat", list, "Table"];

but it produces:

{112.47146693521316, 527.3909029875797} {593.8622181250886, 130.21649411431008}
...
$\endgroup$
  • 4
    $\begingroup$ Your data list is malformed. The last element, list[[-1]] is much larger and shaped differently than the other elements: Dimensions@list[[-1]] returns {2, 151, 2}. That is why you get {2727, 2} when you look at list. But if you look at the rest of the list, Dimensions@Most@list gives {2726, 2, 2} which is why you export like that. If you ignore that last element, you can use Export["list.dat", Flatten /@ Most[list], "Table"]; $\endgroup$ – Jason B. May 27 '16 at 10:59
  • $\begingroup$ @JasonB: I updated the data file and the question. Dimensions@coordinates[[-1]]gives {2,2}. Now your Export line produces what I need. Thank you. $\endgroup$ – mrz May 27 '16 at 12:53
3
$\begingroup$

You are trying to export an Array as a Table, and the system is taking each element at the second level and printing it as you would a number, but in this case it is another list. You just need to flatten each 2 by 2 line in order to export as a "Table"

Export["list.dat", Flatten /@ list, "Table"]//Import//Dimensions
(* {2726, 4} *)
$\endgroup$
  • $\begingroup$ When I do the following: formattedList = NumberForm[#, {8, 4}] & /@ list and then Export["list.dat", Flatten /@ formattedList, "Table"] it fails ? $\endgroup$ – mrz May 28 '16 at 8:14
  • $\begingroup$ @mrz Not at my PC now but try this: first do the flattening. Then map numberform and then export the result $\endgroup$ – Jason B. May 28 '16 at 8:16

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.