MATLAB: Padding zeros at the end row of a matrix

matrix padding zeros

For a matrix A = Nx2, how to pad [0 0] row at the end of the matrix to make the number of rows divisible by a number d?
example: for A = 9×2 and d = 2 adding 1 [0 0] row at end will make it 10×2

Best Answer

A = [A;zeros(mod(d-mod(size(A,1),d),d),size(A,2))];