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 use listD1 = Table[FindRoot[(*my eqns depending on k*), {k, conc}] to get a list of solutions for the different values of conc = {0.03, 0.06, 0.1, 0.4, 1, 3}. listD1 has the form

{{s1 -> 0.000405499, s2 -> 0.000265293, s3 -> 0.000194383, V1 -> 0.019469, V2 -> 0.00823285, V0 -> 0.0366434, V3 -> 0., eef -> 0.715569}, 
{s1 -> 0.000974929, s2 -> 0.000464154, s3 -> 0.000291268, V1 -> 0.0319949, V2 -> 0.0123363, V0 -> 0.0732868, V3 -> 0., eef -> 0.704852}, 
{s1 -> 0.00186423, s2 -> 0.000654623, s3 -> 0.000365062, V1 -> 0.0431875, V2 -> 0.0154618, V0 -> 0.122145, V3 -> 0., eef -> 0.698868}, 
{s1 -> 0.00972514, s2 -> 0.00127244, s3 -> 0.000538089, V1 -> 0.0766826, V2 -> 0.0227901, V0 -> 0.488579, V3 -> 0., eef -> 0.688587}, 
{s1 -> 0.0182276, s2 -> 0.00154438, s3 -> 0.000595658, V1 -> 0.0906385, V2 -> 0.0252284, V0 -> 0.862647, V3 -> 0., eef -> 0.685893}, 
{s1 -> 0.0194252, s2 -> 0.00157279, s3 -> 0.000601234, V1 -> 0.0920781, V2 -> 0.0254645, V0 -> 0.914809, V3 -> 0., eef -> 0.685646}}

I tried to export listD1 as Export["file.txt", Transpose[Prepend[Transpose[listD1], conc]], "CSV"] which gives me in principle the right output but contains the s1-> etc. Is there an option to export without the s1-> but instead use it in the first row as label?

the output should be e.g.

conc, s1, s2, s3, .....
0.03, 0.000405499,  0.000265293, 0.000194383
0.06, 0.000974929,  0.000464154, 0.000291268
...
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted
labels = Prepend[listD1[[1, All, 1]], "conc"];
data = Transpose@Prepend[Transpose[listD1[[All, All, 2]]], conc];
Export["~/Desktop/file.txt", Join[{labels}, data], "CSV"]
share|improve this answer
    
This means that the rule s1 -> 244 is also treated as a table like {s1,244}? –  user2758804 Oct 1 '13 at 8:29
    
@user2758804 I'm not sure I get what you're saying, but [[...]] (Part) can be used on any expression not just lists, if that's where the confusion is. –  Pickett Oct 1 '13 at 10:38
    
@user2758804 Maybe have a look at FullForm[s1 -> 244]. –  b.gatessucks Oct 1 '13 at 12:01
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.