I discover that this pseudo code within my code makes my program slow probably because of the for loop and the fact that JJ is not pre-allocated. I will appreciate a faster idea.
JJ=[];for j=0:p JJ=[JJ; repmat(j,[1+((j+1)-1)*2,1])];end
faster vector with repmat
JJ=[];for j=0:p JJ=[JJ; repmat(j,[1+((j+1)-1)*2,1])];end
Best Answer