Return equal values between sets.

1 vue (au cours des 30 derniers jours)
Leor Greenberger
Leor Greenberger le 21 Sep 2011
I have two vectors a and b of different lengths that contain integers. How can I return those values that belong in both a and b? Should I use ismember? ismember seems to return a vector of index numbers, but I could just that in a or b:
[tf, index] = ismember(a, b);
c = b(index);
c = a(index); %same?

Réponse acceptée

Wayne King
Wayne King le 21 Sep 2011
How about intersect()?
x = 1:3;
y = 2:5;
[c,Ix,Iy] = intersect(x,y);
intersect() does not give repetitions though.
Wayne
  1 commentaire
Leor Greenberger
Leor Greenberger le 21 Sep 2011
works perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by