How to compare two vectors with numbers?

1 vue (au cours des 30 derniers jours)
Xin CUI
Xin CUI le 21 Juin 2013
I have a question. I have two vectors A and B, both have a bunch of numbers. A is master and B is slave. Now what I want is to search each number in A and check if it's one of numbers in B (numbers in B is unique). If a number in A is also in B, label the position of that number in A as 1, and 0 otherwise, just like a logical comparison. Is there a command or a few lines to do this? Thanks in advance.

Réponse acceptée

Vishal Rane
Vishal Rane le 21 Juin 2013
  1 commentaire
Xin CUI
Xin CUI le 21 Juin 2013
Great. thank you.

Connectez-vous pour commenter.

Plus de réponses (1)

Wayne King
Wayne King le 21 Juin 2013
A = randi(10,10,1);
B = 1:5:50;
[IA,IB] = ismember(A,B);
  1 commentaire
Xin CUI
Xin CUI le 21 Juin 2013
Thanks a lot. Very handy.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by