uniqueN function would be useful
Latest activity Reply by John D'Errico
on 29 Aug 2024
isequaln exists to return true when NaN==NaN.
unique treats NaN==NaN as false (as it should) requiring NaN to be replaced if NaN is not considered unique in a particular application. In my application, I am checking uniqueness of table rows using [table_unique,index_unique]=unique(table,"rows","sorted") and would prefer to keep NaN as NaN or missing in table_unique without the overhead of replacing it with a dummy value then replacing it again. Dummy values also have the risk of matching existing values in the table, requiring first finding a dummy value that is not in the table.
uniquen (similar to isequaln) would be more eloquent.
Please point out if I am missing something!
5 Comments
This seems like a reasonable enhancement request to file with Technical Support, though if it gets implemented the way it would be implemented might not be as a new function but as an option for the existing functions. Would you want all six of the set functions (intersect, ismember, setdiff, setxor, union, and unique) to have new <name>n versions? Or would having some or all of them accept a flag (similar to the order flag and occurrence flag) be acceptable?
Why not write your own? Shouldn't be too difficult, and you'll have it to use from now on (while waiting for Mathworks to implement, if they ever do).