Say I have an array X=[1,2,3,4,5] and I want to duplicate the array twice in the following format:
[1,1,2,2,3,3,4,4,5,5]
What would be the easiest option?
Thanks~
Simply using matrix multiplication:
Y = [1; 1] * X;
Y = Y(:)';
You can do it in one line with RESHAPE function:
Y = reshape([1; 1] * X,1,[]);
Alternatively you can use REPMAT function:
Y = reshape(repmat(X,2,1), 1,[]);