필터 지우기
필터 지우기

finding the common numbers in 2 arrays

조회 수: 20 (최근 30일)
Jonathan Bird
Jonathan Bird 2018년 2월 19일
댓글: Jonathan Bird 2018년 2월 19일
I want to compare two arrays each containing 6 numbers e.g. [1,2,3,4,5,6] and [4,8,6,10,11,12]. I want to determine how many numbers are common to both arrays (not necessarily in the same location) so the above would yield an answer of 2 as 4 and 6 are common to both. Thanks!

채택된 답변

Jan
Jan 2018년 2월 19일
See:
doc ismember
With code:
a = [1,2,3,4,5,6]
b = [4,8,6,10,11,12]
nCommon = sum(ismember(a, b))
Maybe the inputs are not unique, then apply unique() at first.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by