How to find an array with all common elements?

9 Ansichten (letzte 30 Tage)
Mariam Shahab
Mariam Shahab am 25 Nov. 2022
Kommentiert: Mariam Shahab am 25 Nov. 2022
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 25 Nov. 2022
a= [1 1 1 0 1];
b= [1 0 1 1 0];
a(a == b)
ans = 1×2
1 1

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by