PDA

View Full Version : Creating Matrix from List in Mathematica


tau1777
Jul21-11, 06:33 PM
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.

Bill Simpson
Jul21-11, 08:48 PM
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}}

tau1777
Jul21-11, 08:59 PM
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.