Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

What you want is a comma separated list.

Export["~/Desktop/file.txt", Flatten /@ Transpose[pts1], "CSV"]
share|improve this answer
    
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. –  user2758804 Sep 29 '13 at 15:58
    
@user2758804 My bad, I updated the code. –  Pickett Sep 29 '13 at 16:03
    
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) ? –  user2758804 Sep 29 '13 at 16:07
    
Is there an equivalent version of Flatten /@ Transpose[pts1] in the form Flatten[Transpose[pts1]]? –  user2758804 Sep 29 '13 at 16:10
    
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 (/@). –  Pickett Sep 29 '13 at 16:13
add comment
data // Transpose // Flatten // Partition[#, 6] & // 
  Export["test.csv", #] &
share|improve this answer
    
Is there a universal version of it? e.g. which also works for 4 data sets? –  user2758804 Sep 29 '13 at 15:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.