Find first common element in 2 vectors
Show older comments
I have 2 vectors, A and B, with identical values but in different orders. How do I find the first common element between them? For example, I have 2 vectors as shown below. How would I return the value "25"?
A = [10 25 36 41 53]
B = [53 41 25 10 36]
Thanks in advance for any help!
4 Comments
Voss
on 4 Apr 2022
How do you decide that 25 is the first common element between A and B in the example? Why not 10, for instance?
KSSV
on 4 Apr 2022
REad about ismember.
Matt J
on 4 Apr 2022
I want index 25 because it is the first common index that is smallest in the two vectors.
No, 10 is smaller than 25.
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!