Equality test not working?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (3)
Andrew Newell
il 22 Dic 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 Commenti
Jan
il 22 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Bar Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!