Equality test not working?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Andrew Newell
el 22 de Dic. de 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 comentarios
Jan
el 22 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Bar Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!