A general question about intersect

조회 수: 1 (최근 30일)
David McVea
David McVea 2019년 11월 10일
댓글: David McVea 2019년 11월 10일
Hello -
I have a general question. I can provide specifics if needed.
How is it possible for
size(intersect(MyData(i),MyData))
to be not equal to
size(i)
Put another way, how can the intersect of a subset of a vector and the original vector not be the entire subset of the vector? I seem to have a case where it is and I can't understand how that can be. It seems impossible, by defintion.
Thanks.

채택된 답변

Walter Roberson
Walter Roberson 2019년 11월 10일
  1. Duplicates in the data. An element that occurs more than once among the MyData(i) will only result in one output
  2. Duplicates in the i values have the same effect.
  3. NaN == NaN is never true, so the results of intersect() remove all NaN
  댓글 수: 1
David McVea
David McVea 2019년 11월 10일
Thank you. the presence of duplicates was the reason.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 11월 10일
Because one element, MyData(i), does not necessarily match every single element of MyData. For example 2 will match only 1 element of this three element vector [1, 2, 3]. It matches only element #2 and does not match element #1 or element #3 so the length will be only 1, NOT 3.
  댓글 수: 1
David McVea
David McVea 2019년 11월 10일
Thanks for your reply - I'm not sure this is exactly what I'm asking. from your example,
length(2) is 1, and length(intersect(2,[1 2 3]) is 1. So length(MyData(i)) equals length(i)
I think you are answering how
length(intersect(MyData(i),MyData))
can be different from
length (MyData)
I'm asking how
length(intersect(MyData(i),MyData))
can be different from
length(i)
Thanks.

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by