Ok so the question is i need to write a function “copymatrix[]” such that if A and B are matrices then copymatrix[A,B,col,row] makes a copy of B inside A by replacing A[[ i + col, j+row]] by B[[i,j]]. Assume that B fits inside A.. Im just not sure on how to define the matrices [A,B]. Thanks
Something like this works:
ClearAll[CopyMatrix]
CopyMatrix[a_, b_, col_Integer, row_Integer] := Module[{c = a, dimx, dimy},
{dimx, dimy} = Dimensions[b];
c[[row ;; row + dimx - 1, col ;; col + dimy - 1]] = b;
c
]
a = RandomReal[1, {10, 10}];
b = {{1, 1, 0}, {0, 2, 2}};
a // MatrixForm
b // MatrixForm
CopyMatrix[a, b, 3, 5] // MatrixForm
Note that there is no error checking in place yet: so make sure col and row are not too big or negative, and matrix b is smaller than matrix a…
What are the dimx,dim y? Is that the values or size of the matrix?