Concise way to compare/find multiple values

44 vues (au cours des 30 derniers jours)
Jurgen
Jurgen le 15 Déc 2017
Commenté : Jurgen le 15 Déc 2017
If I have a matrix of integers called A and want to find the mask corresponding to values 1 and 7, I currently do this:
mask = (A == 1 | A == 7);
But is there a conciser way of doing this? Something like A == [1 7]. If I have many lookups I'd need to use a for loop or maybe bsxfun. It feels like there should be some simple way I'm missing.

Réponse acceptée

Birdman
Birdman le 15 Déc 2017
You may try ismember function.
ismember(A,[1 7]);
  1 commentaire
Jurgen
Jurgen le 15 Déc 2017
I knew there was something! :D

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Author Block Masks dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by