How can I determine which values in vector X are NOT in vector Y?

15 vues (au cours des 30 derniers jours)
Lewis Foggie
Lewis Foggie le 6 Avr 2020
Commenté : Birdman le 6 Avr 2020
Consider:
x = [10 20 30]
y = [10 5 20 30]
What's the simplest way you can think of to output a vector Z which tells you which vectors in y appear in x...
Z = [1 0 1 1]
So Z tells you that 10 appears in y and x, 5 appears in y but not x, 20 appears in y and x, 30 appears in y and x.

Réponses (1)

Birdman
Birdman le 6 Avr 2020
Modifié(e) : Birdman le 6 Avr 2020
Z=~ismember(x,y)
It will return
0 0 0
which means every element in vector X are also in vector Y.
  2 commentaires
Lewis Foggie
Lewis Foggie le 6 Avr 2020
Awesome, thank you!!
Birdman
Birdman le 6 Avr 2020
You are welcome.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by