Finding Rows where a condition is satisfied
Mostrar comentarios más antiguos
I have a 2 column matrix (A) consisting of id numbers in each column to a length of around 5000
I have two smaller column vectors (B & C) which lists a smaller section of id's.
In the first case I want to find rows in A which include an id found in B.
In the second case I want to find rows in A which contain an id found in B & C, or C & B (column order doesn't matter).
I have attempted this by:
[ia ib] = ismember(A(:,1), B);
But this checks only if B is in the first column, ignoring entries where it may be in the second. I would like the rows where one column contains an id from B to then added to a new matrix, D.
I'm looking at doing the same if a row has an id from B and C (not just one column, either column in either order) and adding this information to new matrix E.
Kind Regards,
Dwayne
1 comentario
Walter Roberson
el 10 de Sept. de 2019
This is not correct.
>> [ia, ib ] = ismember(4, [1 2; 3 4])
ia =
logical
1
ib =
4
4 only occurs in the second column of B, but it was found.
When you use ismember() without the 'rows' option, then the second argument is treated as-if you had used (:) with it, like ismember(A(:,1), B(:))
If you are not getting a match then it is for some other reason.
Respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!