Equality test not working?
3 views (last 30 days)
Show older comments
Could someone please explain me this:
>> % uniqueness for the sets DOES NOT WORK! oh why?
iseq=isequal(unique([set01,set02]),[set01,set02])
diff=setdiff([set01,set02],unique([set01,set02]))
diff2=setdiff(unique([set01,set02]),[set01,set02])
--
iseq = 0
diff = Empty matrix: 1-by-0
diff2 = Empty matrix: 1-by-0
>>
0 Comments
Answers (3)
Andrew Newell
on 22 Dec 2011
The documentation says "c = setdiff(A, B) returns the values in A that are not in B. " The function unique extracts one copy of each element, so each element in [set01,set02] is also in unique([set01,set02]) and vice versa. The only difference is how many times they are repeated.
EDIT: This implements what you are trying to do:
s = [set01,set02];
[u, m] = unique(s);
notm = setdiff(1:length(s),m);
diff = s(notm)
0 Comments
Jan
on 22 Dec 2011
The unique function sorts its input data. Therefore if "[set01, set02]" is unsorted, it does not equal "unique([set01, set02])", although both contain the same elements.
Try this:
iseq = isequal(unique([set01,set02]), sort([set01,set02]))
Another reason can be repeated elements in set01 and/or set02.
0 Comments
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!