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