How to find the common values in two arrays

1,077 views (last 30 days)
Suppose I have two vectors
a= 1 2 3 4
b= 4 5 6 7 9
How do I find which value is common to both
in above case it is 4

Accepted Answer

Thomas
Thomas on 28 May 2012
You need the intersect command
doc intersect
in your case
[val,pos]=intersect(a,b) % gives common val and its position in 'a'

More Answers (0)

Categories

Find more on Data Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!