MATLAB: How Zero padding inside a matrix

padsignal processingzerozero padding

Hello, how can i zero pad inside a matrix ? For example :
if true
% code
end
A = [ 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16]
And i want
A = [ 1 2 3 4
5 6 7 8
0 0 0 0
0 0 0 0
......
0 0 0 0
0 0 0 0
9 10 11 12
13 14 15 16]
I know padarray can zero pad but only outside not in the inside.. Thank you.

Best Answer

Create a second matrix of zeros, then assign the appropriate rows of your first matrix to the rows you want in the second matrix:
A = [ 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16];
Desired_Rows = 10; % Pick A Number
B = zeros(Desired_Rows, size(A,2));
B([1:2 end-1:end],:) = A
B =
1 2 3 4
5 6 7 8
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
9 10 11 12
13 14 15 16
Related Question