How create a subset of rows in a matrix

97 views Asked by At

I have a matrix, and I have an n x 1 column vector whose entries in each row are numbers corresponding to a specific row in the matrix. I want to create a new matrix comprised of only the rows specified in the column vector. How can I do this?

1

There are 1 answers

0
Tommaso Belluzzo On BEST ANSWER
% Your matrix...
A = [
  1 1 3 4
  2 3 5 5
  6 1 2 2
];

% Your vector with indices...
B = [1 3];

% Your subset...
C = A(B,:);