Intersection of two sets keeping all intersected values

조회 수: 14 (최근 30일)
Sean
Sean 2014년 7월 15일
댓글: Marc Compere 2021년 3월 27일
Say I have two sets a, and b such that:
a=[1 2 3 4 5 6 6 6 7 8 9 10]
b=[1 12 113 1 25 3 6 6 ]
intersect(a,b)= 1, 3, 6
I want to take the intersection of these two sets, and keep all values of intersection (i.e. not just the unique values that the intersection function outputs).
That is, I want:
intersect(a,b)= 1, 3, 6, 6
  댓글 수: 1
Marc Compere
Marc Compere 2021년 3월 27일
this is certainly a valid concern.
there needs to be an option to do this natively. this is not the expected behavior of a set intersection. this is expected behavior of a unique set intersection. unique is ok but there needs to be an option for non-unique similar to 'stable'

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 15일
a=[1 2 3 4 5 6 6 6 7 8 9 10]
b=[1 12 113 1 25 3 6 6 ]
out=a(ismember(a,b))
  댓글 수: 1
Marc Compere
Marc Compere 2021년 3월 27일
this is helpful but should be a default within the set interction function

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

추가 답변 (1개)

Ben11
Ben11 2014년 7월 15일
Try this:
a(ismember(a,b))
ans =
1 3 6 6 6
6 appears 3 times since it is at 3 locations in a.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by