how to get values of a matrix in MATLAB where the indices are given in a nx2 array
matlab, matrix
Solution
I guess this is what you are looking for:
A(sub2ind(size(A),B(:,1),B(:,2)))
Problem
I have a matrix `A` of size nRows x nCols. I have a `nx2` matrix `B` which contains indices of the matrix `A`. I want to get the values of `A` at the indices given in `B`. lets say, ``` B = [1, 2; 2, 3; 3, 4] A(1,2) = 1 A(2,3) = 2 A(3,4) = 1 ``` I want to know any Matlab command which gives the following, given `A` and `B` (I don't want to use loops): ``` [1 2 1] ```