Why does setdiff answer depend on order of arguments?
조회 수: 10 (최근 30일)
이전 댓글 표시
>>bob = {'a','b','c'};
>>bill = {'a','b','c', 'd','e'}
As expected,
>>A = setdiff(bill,bob)
A =
'd' 'e'
BUT
>> B = setdiff(bob,bill)
B =
Empty cell array: 1-by-0
WHY??
댓글 수: 0
채택된 답변
Steven Lord
2019년 9월 9일
Were you expecting the output to contain elements that are only in one of the inputs but not both? That's not what setdiff does. If that is what you want to do, use setxor instead.
댓글 수: 2
Stephen23
2019년 9월 10일
편집: Stephen23
2019년 9월 10일
It is worth nothing that MATLAB setdiff follows the standard mathematical definition of "set difference", which is defined as A\B (i.e the elements of A that are not in B):
etc.
Although this is the accepted mathematical definition, the term "set difference" is rather ambiguous in common english. It would be nice if it used terms whose meaning was obvious.
추가 답변 (2개)
madhan ravi
2019년 9월 9일
편집: madhan ravi
2019년 9월 9일
bob not in bill (nothing unique all elements of bob belong to bill)
help setdiff
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!