How to find same unique in two different size arrays?

조회 수: 14 (최근 30일)
Ilya Dikariev
Ilya Dikariev 2022년 6월 1일
댓글: Ilya Dikariev 2022년 6월 1일
Assuming we have two different array sizes with similar items in it. How to find number of common items in these arrays?
for ex:
x=[1 22 22
3 8 19];
y=[22 10 19 35];
here answer must be 2, reffering to 22 and 19.
Any good ideas? And also, would that be possible to do it without using loop since actual data size is relatively big?

채택된 답변

Fabio Freschi
Fabio Freschi 2022년 6월 1일
Use ismember
% data
x=[1 22 22
3 8 19];
y=[22 10 19 35];
% engine
[iii,jjj] = ismember(y(:),x(:));
countCommon = sum(iii)
entryCommon = y(iii)
  댓글 수: 1
Ilya Dikariev
Ilya Dikariev 2022년 6월 1일
I was scratching my head with two different loops, thanks )

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by