Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How to compare two vectors with numbers?

Asked by Xin CUI

Xin CUI

on 21 Jun 2013
Accepted Answer by Vishal Rane

Vishal Rane

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.

0 Comments

Xin CUI

Xin CUI

Products

No products are associated with this question.

2 Answers

Answer by Vishal Rane

Vishal Rane

on 21 Jun 2013
Accepted answer

try ismember

1 Comment

Xin CUI

Xin CUI

on 21 Jun 2013

Great. thank you.

Vishal Rane

Vishal Rane

Answer by Wayne King

Wayne King

on 21 Jun 2013
A = randi(10,10,1);
B = 1:5:50;
[IA,IB] = ismember(A,B);

1 Comment

Xin CUI

Xin CUI

on 21 Jun 2013

Thanks a lot. Very handy.

Wayne King

Wayne King

Contact us