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)
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
user9003011
  • 306
  • 1
  • 10

3 Answers3

2

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
bla
  • 25,846
  • 10
  • 70
  • 101
2

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
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
1

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)));
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147