MathGroup Archive 2008

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

Search the Archive

Re: Package to 'graft' Lists onto Matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87707] Re: [mg87667] Package to 'graft' Lists onto Matrices
  • From: robert prince-wright <robertprincewright at yahoo.com>
  • Date: Wed, 16 Apr 2008 04:59:59 -0400 (EDT)

Thanks Craig - you may have spotted that I meant to add/insert columns! 
   
  I still think Wolfram should have a simple, optimised, function that allows you to Insert and add matrices, vectors / lists into defined positions in an existing matrix. Something like:
   
  Graft[ list, mat, Column, 3] - which inserts list into matrix mat after column 3. 
  Graft[ list, mat, Row, 2]  - which inserts list into matrix mat after row 2. 
   
  Or how about
   
  Graft[ mat1, mat2, Column, 3 - to insert a matrix.
   
  I find myself rethinking how to do this every now and then. (Your probably thinking I should just write a package - but what a waste of time for something so fundamental.)
   
   
   
  

W_Craig Carter <ccarter at mit.edu> wrote:
  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



Robert Prince-Wright
Houston
TX, 77006
USA


  • Prev by Date: Re: Numerical integration and list of points
  • Next by Date: Re: smart change of variables?
  • Previous by thread: Re: Re: Package to 'graft' Lists onto Matrices
  • Next by thread: How to solve this simple equation?