Re: Appending to a matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg38549] Re: Appending to a matrix?
- From: Bill Rowe <listuser at earthlink.net>
- Date: Wed, 25 Dec 2002 03:12:56 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On 12/24/02 at 6:40 AM, cfgauss at pants.attbi.com (Jeremy) wrote: >How do I append a column vector to the end of a matrix in mathematica? > > For example, I want to turn: > [1 2 3] [1] > [4 5 6] and [1] > [7 8 9] [1] > >into > > [1 2 3 1] > [4 5 6 1] > [7 8 9 1] A couple of ways come to mind such as Transpose[Join[Transpose[m],{c}]] or MapThread[Flatten[{#1,#2}]&,{m,c}] or using the package Statistics`DataManipulation` RowJoin[m,Transpose[{c}]] In these examples m is the matrix you want c appended to and c is a flat list. Note these may not be the fastest methods, something that might matter for much larger matrices