0
$\begingroup$

I have a ListPlot where I extract my data again using pts1 = Cases[(*I put my list plot here*), , x_Point :> First@x, Infinity]; which gives me the data as nested list

    { {{0.03, 2.21325*10^22}, {0.06, 3.64418*10^22}, {0.1, 4.778*10^22}, {0.4, 7.90494*10^22}, 
      {1., 9.8882*10^22}, {3., 1.20734*10^23}}, {{0.03, 1.24205*10^22}, {0.06, 1.7829*10^22}, 
      {0.1, 2.14653*10^22}, {0.4, 2.96566*10^22}, {1., 3.39166*10^22}, {3., 3.80355*10^22}}, 
      {{0.03, 7.93772*10^21}, {0.06, 1.05402*10^22}, {0.1, 1.21384*10^22}, {0.4, 1.54018*10^22}, 
      {1., 1.69508*10^22}, {3., 1.83693*10^22}}}

How can I export this data, so that I have a file with 3x2 colums for the three data sets, so something like

0.03, 2.21325*10^22,  0.03, 1.24205*10^22,0.03, 7.93772*10^21
0.06, 3.64418*10^22, etc.
0.1, etc.
etc.
$\endgroup$
0
$\begingroup$

What you want is a comma separated list.

Export["~/Desktop/file.txt", Flatten /@ Transpose[pts1], "CSV"]
$\endgroup$
  • $\begingroup$ actually I need the transpose of the output file. So not 0.03 0.03 0.03 in the first column but 0.03 0.06 0.1 etc. $\endgroup$ – user2758804 Sep 29 '13 at 15:58
  • $\begingroup$ @user2758804 My bad, I updated the code. $\endgroup$ – C. E. Sep 29 '13 at 16:03
  • $\begingroup$ Thanks. Is there an easy way to complement the output file by column labels in the first row, eg. Hz, density(1ML), Hz, density(2ML), Hz, density(3ML) ? $\endgroup$ – user2758804 Sep 29 '13 at 16:07
  • $\begingroup$ Is there an equivalent version of Flatten /@ Transpose[pts1] in the form Flatten[Transpose[pts1]]? $\endgroup$ – user2758804 Sep 29 '13 at 16:10
  • $\begingroup$ 1) Yes, use Prepend to add such a row to Transpose[pts1]. 2) No, Flatten works from the outside in, so I think it's not possible to do it with Flatten without also using Map (/@). $\endgroup$ – C. E. Sep 29 '13 at 16:13
0
$\begingroup$
data // Transpose // Flatten // Partition[#, 6] & // 
  Export["test.csv", #] &
$\endgroup$
  • $\begingroup$ Is there a universal version of it? e.g. which also works for 4 data sets? $\endgroup$ – user2758804 Sep 29 '13 at 15:58

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.