MATLAB Answers

Martin
0

find dublicated value in a column and return the whole row

Asked by Martin
on 22 Oct 2018
Latest activity Commented on by madhan ravi
on 22 Oct 2018
imagine I have this:
A = [ 1 ; 3 ; 5 ; 6 ; 9 ]
and
B = [ 1 4 ; 2 7 ; 3 5 ; 9 10 ]
I need to end up with:
C = [ 1 4 ; 3 5 ; 9 10 ]
In B(:,1) column I need to find those from A that match, and if so, return the full rows of B. Hope I am clear

  0 Comments

Sign in to comment.

Products

1 Answer

Answer by madhan ravi
on 22 Oct 2018
 Accepted Answer

A = [ 1 ; 3 ; 5 ; 6 ; 9 ]
B = [ 1 4 ; 2 7 ; 3 5 ; 9 10 ]
idx=ismember(B(:,1),A)
C = B(idx,:)

  3 Comments

If it answers your question please accept the answer so that other people know the question had been solved

Sign in to comment.