0
$\begingroup$

I have a super simple data wrangling question that I can't seem to figure out (I am new to Mathematica). Basically I'm not sure what function to use. I have two parameters, paramc3 and paramS, that I used to get the output, values, in previous code. I simply want to create a matrix, with column headings corresponding to each paramS value and rows corresponding to each paramc3 value and then export as a CSV. I tried:

paramc3 = Table[c3, {c3, 0, 2, 0.1}];
paramS = Table[s, {s, 0, 1, 0.1}];
values = {{unstable, unstable, unstable, unstable, unstable, unstable,
     unstable, unstable, unstable, unstable, 
    unstable}, {0.19754659869364347`, 4.878410368867524`, unstable, 
    unstable, unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable}, {unstable, unstable, unstable, unstable, 
    4.64757211994509`, unstable, unstable, unstable, unstable, 
    unstable, unstable}, {unstable, unstable, unstable, unstable, 
    unstable, 5.58201356941801`, 3.059853547091468`, unstable, 
    unstable, unstable, unstable}, {unstable, unstable, unstable, 
    unstable, unstable, unstable, 5.484947253911817`, 
    2.6379330262422918`, unstable, unstable, unstable}, {unstable, 
    unstable, unstable, unstable, unstable, unstable, 
    0.794348167322319`, 4.708767525484398`, unstable, unstable, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, 5.507247245016035`, 2.3277428641553386`, 
    unstable, unstable}, {unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, 4.5774724131840365`, 
    3.7729720387151344`, unstable, unstable}, {unstable, unstable, 
    unstable, unstable, unstable, unstable, unstable, unstable, 
    4.7172200222598395`, unstable, unstable}, {unstable, unstable, 
    unstable, unstable, unstable, unstable, unstable, unstable, 
    5.286941004368434`, unstable, unstable}, {unstable, unstable, 
    unstable, unstable, unstable, unstable, unstable, unstable, 
    5.486421676853467`, unstable, unstable}, {unstable, unstable, 
    unstable, unstable, unstable, unstable, unstable, unstable, 
    5.184287940321331`, 1.1581471747603866`, unstable}, {unstable, 
    unstable, unstable, unstable, unstable, unstable, unstable, 
    unstable, 3.8276962693927357`, 2.0886269128201467`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 2.835722444419939`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 3.44873547223903`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 3.956627333693203`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 4.377732263494166`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 4.723815230292599`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 5.0020155840974025`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 5.215774894883028`, 
    unstable}, {unstable, unstable, unstable, unstable, unstable, 
    unstable, unstable, unstable, unstable, 5.365136687453673`, 
    unstable}};
m = MatrixForm[{values}, {paramS}, {paramc3}]
Export["Desktop/matrix.csv", m, "CSV"]

along with other functions like Thread, Distribute etc. I feel like this should be super simple and yet I'm so stuck. Thanks in advance.

$\endgroup$
2
  • $\begingroup$ Welcome to MSE. Take a look at the documentation for Prepend, Append and Transpose. $\endgroup$ Aug 31 at 19:10
  • $\begingroup$ Thank you Rohit for the guidance on which functions to explore. $\endgroup$
    – Clara
    Aug 31 at 19:12
3
$\begingroup$
Export["matrix.csv", values, TableHeadings -> {paramc3, paramS}]
$\endgroup$
2
$\begingroup$

One of possible ways:

out = Transpose@
  Prepend[Transpose@Prepend[values, paramS], Prepend[paramc3, ""]]

Export["matrix.csv", out, "CSV"]
$\endgroup$
1
  • $\begingroup$ Thank you so much Domen! This works. $\endgroup$
    – Clara
    Aug 31 at 19:11

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.