Tony's Trick
Here is a technique to replicate a vector of size M-by-1 N times, to create a new matrix of sizeM-by-N. This method is known as Tony's Trick. The first column of the vector is indexed (or referenced) n times:v = (1:5)' n = 3; M = v(:,ones(n,1))
gives
M = 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5