Finding elements common to both arrays

1 次查看(过去 30 天)
Given
A = [1 2 3 6 7 9 10];
B = [4 7 8 10];
How would I determine that 7 and 10 are common to both vectors?
find(ismember(A,B))
appears to return the index of A that has the number(s) shared with B, which is not quite what I want. I want to return the values 7 and 10. How do I do that? I have very large vectors, but here I'm giving a simple example.

采纳的回答

Torsten
Torsten 2022-4-20
Use
v = intersect(A,B)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by