Why does setdiff answer depend on order of arguments?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Brian Wilson
am 9 Sep. 2019
Bearbeitet: Stephen23
am 10 Sep. 2019
>>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 Kommentare
Akzeptierte Antwort
Steven Lord
am 9 Sep. 2019
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 Kommentare
Stephen23
am 10 Sep. 2019
Bearbeitet: Stephen23
am 10 Sep. 2019
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.
Weitere Antworten (2)
madhan ravi
am 9 Sep. 2019
Bearbeitet: madhan ravi
am 9 Sep. 2019
bob not in bill (nothing unique all elements of bob belong to bill)
help setdiff
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!