Is there an easy way to index into a matrix with a vector to extract the jth column of the matrix for each row? As an example, lets take the 4 x 4 matrix created by
A = magic(4);A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
I have a vector which describes which columns I'd like to extract:
ii = [1; 2; 1; 2]ii = 1 2 1 2
Is there a straightforward way of indexing into the matrix to return the vector:
result = 16 11 9 14
Best Answer