B = zeros(256,256);
B(1:size(A,1),1:size(A,2)) = A;
B(end-size(A,1)+1:end, 1:size(A,2)) = A;
With obvious generalizations to upper right and lower right
c = floor((size(B)-size(A))/2);
B(c(1)+1:c(1)+size(A,1), c(2)+1:c(2)+size(A,2)) = A;
The centering algorithm biases towards the upper left if the sizes are not both even or not both odd.
Best Answer