MATLAB: Locate an element in an array

MATLAB: Locate an element in an array


Hello, I wanted to ask about how to locate the items that I have in a matrix or vector in a larger matrix and remove the row in which it is located. For example I have the following matrix (in my case is bigger than this) :
a =
3.4000 5.5000 8.6000
2.4000 6.3000 7.7000
7.7000 2.3000 6.9000
8.8000 5.7000 9.9000
And another where the elements that interest me in to find are :
b =
6.3000 1.0000
5.7000 2.0000
And what I want and I want is to find the elements of the first column of b in the second column of a; and once found remove the entire row where these elements are b , resulting in :
res =
2.4000 6.3000 7.7000
8.8000 5.7000 9.9000
6.3000 and 5.7000 which are the elements of b found in a with its corresponding row. Thanks in advanced.

Best Answer

  • res = a(ismember(a(:,2),b(:,1)),:);
  • Add a Comment

    Your email address will not be published. Required fields are marked *