MATLAB: Replacing a for loop

for loopMATLABmatrix

Hello all,
I have a simple piece of code that I would like to get rid of the for loop. I would appreciate your help.
for n=1:K
idx=row((((n-1)*dc)+1):(n*dc));
end
where as an example K=4, dc=2, and row=[1;3;2;3;1;4;2;4];

Best Answer

t = reshape(row, dc, []);
idx = t(:,1:K);