Say I have a matrix n by d Aand I want to rewrite the entries in some columns. For this, I compute the permutations 1 ... nas
idx1 = randperm(n)'
idx2 = randperm(n)'
Then I could do:
A(:,1) = A(idx1,1)
A(:,2) = A(idx2,2)
However, I do not want to do this with for-loop, as it will be slow. Say I have a matrix n by d Aand an index matrix n by d IDXthat defines permutations, there is a faster equivalent to the following for-loop:
for i = 1:d
A(:,i) = A(IDX(:,i),i);
end
source
share