How to cross-reference values in one array with another (of different sizes)

5 views (last 30 days)
I have two arrays, each containing strings which define subject IDs.
The arrays contain different numbers of subjects, and overlap significantly (but not entirely).
How do I create a logical index for each cell in array 1, where values of True(1) are given when that string appears in both arrays, and values of False(0) are given when the string only appears in array 1.
I could probably do this with a for loop for each cell in array 1 but I feel like there is a better, more obvious way.
Thank you!
EXAMPLE:
ARRAY1: [ID1 ID2 ID3 ID4 ID5 ID6 ID7 ID8 ID9]
ARRAY2: [ID2 ID9 ID4 ID11]
DESIRED OUTPUT: [0 1 0 1 0 0 0 0 1 0]

Accepted Answer

Stephen23
Stephen23 on 29 Sep 2017
ismember(Array1,Array2)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!