MATLAB: Expanding the existing matrix

matrix operations

I have a matrix like this.
M=[1 2 3;
4 5 6].
I want to expanding it into
M'=[1 1 2 2 3 3;
1 1 2 2 3 3;
1 1 2 2 3 3;
4 4 5 5 6 6;
4 4 5 5 6 6;
4 4 5 5 6 6].
I try to do this.but stil i could not get correct result?

Best Answer

kron(M,ones(3,2))
or
m = 3;
n= 2;
s = size(M);
out = reshape(permute(reshape(repmat(M,m,n),s(1),m,s(2),n),[2 1 4 3]),m*s(1),[]);