Date: Dec 28, 2012 8:14 AM
Author: Daniel
Subject: How to vectorize this matrix indexing

Hello,

Does anyone have an idea on vectorizing the for loop in the following program?

A=rand(10,4)
b=[2 4 1 3 2 3 1 2 4 1]'
r=zeros(10,1);

for m=1:10
r(m)=A(m,b(m));
end

'b' is an index array for selecting a certain column. The index is different for different rows. Any suggestions? Thanks.

Daniel