Return Unique Element with a Tolerance

后端 未结 7 1368
无人共我
无人共我 2020-11-27 06:40

In Matlab, there is this unique command that returns thew unique rows in an array. This is a very handy command.

But the problem is that I can\'t assign tolerance to

7条回答
  •  被撕碎了的回忆
    2020-11-27 06:50

    This is hard to define well, assume you have a tolerance of 1. Then what would be the outcome of [1; 2; 3; 4]?

    When you have multiple columns a definition could become even more challenging.

    However, if you are mostly worried about rounding issues, you can solve most of it by one of these two approaches:

    1. Round all numbers (considering your tolerance), and then use unique
    2. Start with the top row as your unique set, use ismemberf to determine whether each new row is unique and if so, add it to your unique set.

    The first approach has the weakness that 0.499999999 and 0.500000000 may not be seen as duplicates. Whilst the second approach has the weakness that the order of your input matters.

提交回复
热议问题