Let's say I have a matrix A, whose first column are IDs, and a vector B, containing certain IDs in a random order (and some of them might be missing etc).
How do I select the rows of A with matching IDs in the order given by B?
Example:
Using the matrices
A = [2, 0.4, 0.3;
9, 0.2, 0.8;
3, 0.3, 0.4;
5, 0.1, 0.5];
B = [9; 2; 5];
I would like to get the matrix
C = [9, 0.2, 0.8;
2, 0.4, 0.3;
5, 0.1, 0.5];
sortingneeded thereafter. Of course, this is assuming OP here wants to use the vector as an indexing array. - DivakarA(ismember(A(:,1),B),:)---- if you do care about the order and the size of B is fixed to 3 ----A([find(A(:,1)==B(1)), find(A(:,1)==B(2)), find(A(:,1)==B(3))],:)- yakoudbz