How to find numbers in one vector but not in the other vector?

For example, I have two vectors a=[2 3 4 6], and b=[3 4 5]. How do I find the index in a indicating the numbers that are not in b. In this example, a(1)=2 is not in b, a(3) = 6 is not in b either. So, the answer should be [2 4]. Is there a faster way doing this than using a full loop checking on each number?

Answers (1)

value=setdiff(a,b)
If you want values and index
[value,idx]=setdiff(a,b)

Categories

Tags

Asked:

on 22 May 2013

Community Treasure Hunt

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

Start Hunting!