Adding zeros to matrix

Illustration
Anjali Sharma - 2022-02-28T12:31:12+00:00
Question: Adding zeros to matrix

I have to do image processing. I have one data with 100 x 100 matrix and another with 300 x 300 matrix. I want to add zeros to 100 x100 matrix to equalize it like 300 x300 but zeros to be added after 100 x 100 equally and not in particular end.

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

% Replace this with your image
Image100 = peaks(100)+10;

%Centering padding in 4 sides
PadImage300 = zeros(300,300,size(Image100,3),class(Image100));
PadImage300(101:200,101:200,:) = Image100;

imagesc(PadImage300)

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!