MATLAB: How to avoid for loop when indexing

for loop

Hello,
I have the following for loop, where pairs(500×10), is there to calculate cc without for loop?
for i=1:500
cc(i,:)=pairs(i,pairs(i,:));
end

Best Answer

s = size(pairs);
index = sub2ind(s, repmat((1:s(1)).', 1, s(2)), pairs)
cc = pairs(index)