Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zero padding a matrix

Tags:

matrix

matlab

I have a 16X16 matrix. I have to add it to a 256X256 matrix. Can anyone help me how to make this 16X16 matrix into 256X256 filling the remaining with zeros?

like image 419
buddy Avatar asked Dec 02 '22 03:12

buddy


2 Answers

Matlab automatically pads with zeros if you assign something to an element outside of the original size.

>> A = rand(16, 16);
>> A(256, 256) = 0;
>> size(A)
ans =
   256   256
like image 155
groovingandi Avatar answered Dec 03 '22 15:12

groovingandi


padded = zeros(256,256);
data = rand(16,16);
padded(1:16,1:16) = data;
like image 35
zellus Avatar answered Dec 03 '22 15:12

zellus