Initial matrix is A = [ [1 2 3; 4 5 6; 7 8 9]
. Every row is to be replicated 3 times such that the output matrix is
B = [1 2 3;1 2 3;1 2 3;4 5 6; 4 5 6; 4 5 6; 7 8 9; 7 8 9; 7 8 9]
B = replicate(permute(A,[3 2 1]),3,1)
Initial matrix is A = [ [1 2 3; 4 5 6; 7 8 9]
. Every row is to be replicated 3 times such that the output matrix is
B = [1 2 3;1 2 3;1 2 3;4 5 6; 4 5 6; 4 5 6; 7 8 9; 7 8 9; 7 8 9]
B = replicate(permute(A,[3 2 1]),3,1)
you mean like that?
kron(A,ones(3,1))
ans =
1 2 3
1 2 3
1 2 3
4 5 6
4 5 6
4 5 6
7 8 9
7 8 9
7 8 9
Since R2015a, there is a dedicated function for this: repelem
.
A = [1 2 3; 4 5 6; 7 8 9]
B = repelem(A,3,1)
B =
1 2 3
1 2 3
1 2 3
4 5 6
4 5 6
4 5 6
7 8 9
7 8 9
7 8 9
Or just indexing:
A = [1 2 3; 4 5 6; 7 8 9]; % original matrix
m = 3; % row repetition factor
n = 1; % column repetition factor
B = A(ceil(1/m:1/m:size(A,1)), ceil(1/n:1/n:size(A,2)));