The matrix row are to be increased. Row repetition is allowed and row sequence is not mandatory but expected. The new row size may or may not be divisible by original row size.
A=[1 2 3; 4 5 6; 7 8 9]
B=resize(A,9,3)
This is to be increased to row size of 9 and 11 (two different outputs). Column size remain fixed.
If the output must be zero-padded, you can just index the bottom-right corner of the target matrix and assign it a value of 0
. There is no need to invoke padarray... Matlab will take care of everything else by itself:
A = [1 2 3; 4 5 6; 7 8 9];
B = A;
B(9,3) = 0;
C = A;
C(11,3) = 0;
If you want to perform this with repetitions, you can use the repmat function, but it can only produce size multiples to the respect of the original matrix... hence some more efforts are required for the second target:
A = [1 2 3; 4 5 6; 7 8 9];
B = repmat(A,3,1);
C = repmat(A,4,1);
C = C(1:11,:);
% or C(12,:) = [];
The last alternative I can figure out require some more manual work (for the copy-over). Let's suppose, for example, that you want your target matrices to be zero-padded once again, then:
A = [1 2 3; 4 5 6; 7 8 9];
[A_rows,A_cols] = size(A);
B = zeros(9,3);
B(1:A_rows,1:A_cols) = A;
C = zeros(11,3);
C(1:A_rows,1:A_cols) = A;
Replacing zeros
with ones
or NaN
will return respectively a one-padded or a NaN-padded matrix instead.