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
  • 18,595
  • 13
  • 73
  • 147
  • 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,081
  • 7
  • 36
  • 71
Paolo
  • 13,742
  • 6
  • 28
  • 51