How to compare an array with 2D matrix?

1 visualizzazione (ultimi 30 giorni)
Emmanuel
Emmanuel il 21 Ott 2016
Commentato: Emmanuel il 21 Ott 2016
If I have an array A= [1,2] and matrix B= [3,4;8,6;1,2], How can I say that array A is present in B?

Risposta accettata

KSSV
KSSV il 21 Ott 2016
doc ismember

Più risposte (1)

Image Analyst
Image Analyst il 21 Ott 2016
Try ismember() with the 'rows' option:
[~, matchingRows] = ismember(A, B, 'rows')
  3 Commenti
Image Analyst
Image Analyst il 21 Ott 2016
Emmanuel, try this:
A= [1,2]
B= [3,4;8,6;1,2; 4,5; 1,2]
[inA, inB] = ismember(B, A, 'rows')
matchingRows = find(inB)
Emmanuel
Emmanuel il 21 Ott 2016
Yeah! That works. Thank you very much..

Accedi per commentare.

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by