MATLAB: Repeat matrix element of a given matrix

repeat matrix element

my matrix is x=[2 5 3 6 1]
I want it to make it as y=[2 2 2 2 5 5 5 5 3 3 3 3 6 6 6 6 1 1 1 1]
which function does it?

Best Answer

x = [2 5 3 6 1];
y = reshape(repmat(x, 4, 1), 1, []);
Or:
y = kron(x, ones(1, 4));