MATLAB: Populate Array with duplicate variables

arraysduplicate elements

Hi,
I am trying to duplicate the elements within a Matlab array according to the position of elements of the array.
For instance,
x = [1,2,3,4,5,6,4,2,7,5,3] should become x1 = [1,1,2,2,3,3,4,4,5,5,6,6,4,4,2,2,7,7,5,5,3,3]
Thanks

Best Answer

x = [1,2,3,4,5,6,4,2,7,5,3]
y=[x;x]
y=y(:)'
%Or
n=2
x=repmat(x,n,1);
y=y(:)'