1
$\begingroup$

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
...
$\endgroup$
0

1 Answer 1

2
$\begingroup$
labels = Prepend[listD1[[1, All, 1]], "conc"];
data = Transpose@Prepend[Transpose[listD1[[All, All, 2]]], conc];
Export["~/Desktop/file.txt", Join[{labels}, data], "CSV"]
$\endgroup$
3
  • $\begingroup$ This means that the rule s1 -> 244 is also treated as a table like {s1,244}? $\endgroup$ Oct 1, 2013 at 8:29
  • $\begingroup$ @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. $\endgroup$
    – C. E.
    Oct 1, 2013 at 10:38
  • $\begingroup$ @user2758804 Maybe have a look at FullForm[s1 -> 244]. $\endgroup$ Oct 1, 2013 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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