How to find an array with all common elements?

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개)

카테고리

도움말 센터File Exchange에서 Data Types에 대해 자세히 알아보기

태그

질문:

2022년 11월 25일

댓글:

2022년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by