0

Given the following matrix:

1 1 1
2 2 2
3 3 3

For k = 3, I want the following output:

1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
3 3 3
3 3 3
3 3 3

Is there a smart way to do this in vectorized manner in MATLAB?

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
  • Even though the primary linked duplicate deals with a 1-D vector, the solution extends easily to the 2-D case here. – gnovice Sep 04 '18 at 18:16

1 Answers1

2

You can use repelem:

k = 3;
a =[1 1 1
    2 2 2
    3 3 3]
repelem(a,k,1)
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Paolo
  • 21,270
  • 6
  • 38
  • 69