I have a vector A, for example (1:1:5)' I want to create a new vector B in which each row from vector A is repeated, for example 5 times. So A is [1 2 3 4 5]' and B is [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5]'
I have been able to accomplish this with the for loop below, but this takes much too long as my real vector A is over 2 million rows long. Is there a more computationally efficient way to accomplish this?
numbreps=5; for k=1:size(A); B(k*numbreps:k*numbreps+numbreps-1,1)=A(k,1); end; B(1:numbreps-1)=[];
Best Answer