Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Creating Matrix from List in Mathematica

  1. Jul 21, 2011 #1
    Hi All,

    So I've been trying to create a matrix from a list of numbers and have been unsuccessful so far. Basically I would like to change

    list = {1,2,3,4,5,6,7,8,9}

    into

    matrix =
    1 2 3
    4 5 6
    7 8 9

    The real problem is just a much bigger matrix, but if anyone can tell me how to do this I can do the bigger problem.

    Thanks so much to anyone who helps.
     
  2. jcsd
  3. Jul 21, 2011 #2
    In[1]:= list={1,2,3,4,5,6,7,8,9};matrix=Partition[list,3]
    Out[2]= {{1,2,3},{4,5,6},{7,8,9}}
     
  4. Jul 21, 2011 #3
    Thank you so much Bill. This works like charm. Can't believe I spent a day scouring other forums for this. Thanks for the very quick response time...this was starting to drive me crazy because I was convinced it was a command that I just didn't know and it was.

    Thanks. Thanks. Thanks.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook