How to find numbers in one vector but not in the other vector?
Show older comments
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?
1 Comment
Azzi Abdelmalek
on 22 May 2013
The answer should be [2 6]
Answers (1)
Azzi Abdelmalek
on 22 May 2013
Edited: Azzi Abdelmalek
on 22 May 2013
value=setdiff(a,b)
If you want values and index
[value,idx]=setdiff(a,b)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!