MATLAB: How do i place a 9-by-9 matrix in the center of a 256-by-256 matrix of zeros. Thank you

insert a matrix within a matrixopticspsf

So i am trying to create a PSF array, and i want to place the 9-by-9 PSF array in the center of a 256-by-256 matrix of zeros.

Best Answer

Try this:
M = zeros(255);
M(123:132, 123:132) = randi(9);
figure(1)
imagesc(M)
axis image
grid
You cannot have a (9x9) exactly in the centre of a (256x256) matrix. It is possible to put it in the centre of a (255x255) matrix.