Using a vector as column-indices into rows of a matrix, in Octave
You need to create linear indices for that. Following your example:
octave-3.8.2> a = [1 2 3
4 5 6
7 8 9];
octave-3.8.2> b = [1 3 1];
octave-3.8.2> ind = sub2ind (size (a), 1:rows (a), b);
octave-3.8.2> c = a(ind)
c =
1 6 7
As per my understanding, the way to go about creating a logical matrix is below:
>A = eye(3,3)
>B = [1;3;1]
>A(B,:) =
>
>[ 1 0 0;
> 0 0 1;
> 1 0 0; ]