Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Package to 'graft' Lists onto Matrices

  • To: mathgroup at
  • Subject: [mg87742] Re: [mg87667] Package to 'graft' Lists onto Matrices
  • From: "W_Craig Carter" <ccarter at>
  • Date: Wed, 16 Apr 2008 05:06:34 -0400 (EDT)
  • References: <>

Hello, You might try these:

 mat = RandomInteger[{0, 10}, {5, 7}];
 mat // MatrixForm
 AddRow[mat_?MatrixQ, row_List] := Join[mat, {row}]
 AddRow[mat, {a, b, c, d, e, f, g}] // MatrixForm

 AddColumn[mat_?MatrixQ, column_List] :=
  Transpose[Join[Transpose[mat], {column}]]
 AddColumn[mat, {a, b, c, d, e}] // MatrixForm

 No checking here or matching dimensions, but that could be built in easily.

>   It seems a little daft that that you need to use MapThread and Append to simply graft a row onto an existing matrix!

W. Craig Carter

  • Prev by Date: Re: smart change of variables?
  • Next by Date: Re: mx files
  • Previous by thread: Package to 'graft' Lists onto Matrices
  • Next by thread: Re: Package to 'graft' Lists onto Matrices