MATLAB: Padding an array with some size, and the location

pad

Say that we have an array, and I wanted to resize that array while keeping its content. Something I thought of is "padding". When I tried that, I noticed that the original content had different locations in the new array. How can I pad they array, while keeping the original array content in their same location?
Thanks.

Best Answer

I am not certain what you want, but this may work:
A = randi(10, 5, 4); % Original Array
B = zeros(10); % Preallocate Larger Array
B(1:size(A,1), 1:size(A,2)) = A; % Create Padded Array
EDIT — It creates ‘A’ in ‘B’ such that the addressing (element references) are the same in both ‘A’ and ‘B’ for the original matrix ‘A’.