How to find an array with all common elements?

8 次查看(过去 30 天)
Hi all,
Suppose I have the following two arrays:
a= [1 1 1 0 1];
b= [1 0 1 1 0];
I want to find an array that contains each element common to both a and b. So, the elements can be repeated and they have to be in order. I will appreciate any help on this. Thanks!

采纳的回答

Walter Roberson
Walter Roberson 2022-11-25
a= [1 1 1 0 1];
b= [1 0 1 1 0];
a(a == b)
ans = 1×2
1 1

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by