I want to eliminate the for loop from the code below and vectorize it, but it is a 2 dimensional operation. Can you please help me.
for i=1:10 savingsFull(i,:) = distances(i,9)+distances(9,knnIdx(i,:))-distances(i,knnIdx(i,:)); end here, "distances" is a 10x10 symmetric matrix and "knnIdx" is a 10x2 matrix as below:
1 10 2 10 3 8 4 8 5 4 6 5 7 2 8 4 9 8 10 1 "savingsFull" is also a 10x2 matrix.
bsxfunto vectorize