0

Suppose the input matrix is:

a=[1,2,3; 4,5,6; 7,8,9];

the expect output matrix would be:

[1  1  1  2  2  2  3  3  3 
 4  4  4  5  5  5  6  6  6
 7  7  7  8  8  8  9  9  9]

Is there a neat matlab function to do this? Many thanks for your time and attention.

ntough
  • 333
  • 1
  • 3
  • 8
  • This question surely has a duplicate somewhere; but I suggest looking at the `kron` function...Hint: use `ones(x,y)` as well. I'll let you figure out what `x` and `y` need to be :) – Benoit_11 Jul 10 '15 at 13:26
  • Thanks for introducing 'kron' function to me, Benoit. This is whart I was thinking. 'a = [1,2,3; 4,5,6; 7,8,9]; b=[1;1;1]; c=kron(b,a); reshape(c, [3,9])'. Well, it has more than one functions here though. – ntough Jul 10 '15 at 13:46
  • You're welcome! Use `b = kron(a,ones(1,3))`. Have fun! – Benoit_11 Jul 10 '15 at 13:47

0 Answers0