Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1993
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1993

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

Search the Archive

MatrixInsert

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: MatrixInsert
  • From: HAY at leicester.ac.uk
  • Date: Sat, 23 OCT 93 01:19:54 BST
  • Mailer: Janet_Mailshr V3.4 (23-May-1989)

>> How can I assign a matrix to a part of another matrix?



Mark Fisher's fast one-liner solution inspired a search.

Here is another one - about twice as fast.



MatrixInsert[A_, B_, {r_, c_}] :=

	Block[{rB,r2,c2},

		rB = Length[B];

		{r2,c2} = {r,c} + Dimensions[A] -1; 

		Join[

			Take[B,r-1],

			MapThread[

				Join[Take[#1,c-1],#2,Drop[#1,c2]]&,

				{Take[B,{r,r2}],A}

			],

			Take[B, r2-rB]

		]

	]

	

	Allan Hayes

	hay at leicester.ac.uk





  • Prev by Date: random number seeds
  • Next by Date: NDSolve
  • Previous by thread: Re: Taylor expansion
  • Next by thread: NDSolve