MATLAB: Indexing (extracting value from rows)

logicla indexing rows

I have a 5 x 5 array, A, and a 5 x 1 array, B = [2 3 1 4 3]'. How can I extract the element from each row of A as they occur in B. i.e., I want the 2nd value of row one of A, they 3rd value of row two of A, …, and the 3rd value of row five of A.
Any help would be appreciated.

Best Answer

  • idx=sub2ind(size(A), ones(size(B)), B);