返回具有容差的唯一元素 [英] Return Unique Element with a Tolerance

查看:32
本文介绍了返回具有容差的唯一元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Matlab 中,有这个 unique 命令 返回数组中唯一的行.这是一个非常方便的命令.

但问题是我不能给它分配容差——在双精度中,我们总是必须在一个精度内比较两个元素.是否有内置命令可以在一定容差范围内返回唯一元素?

解决方案

从 R2015a 开始,终于有一个函数可以做到这一点,uniquetol(在 R2015a 之前,参见 我的其他答案):

<块引用>

uniquetol 在容差范围内设置唯一.

   uniquetol 类似于 unique.unique 执行精确比较,而 uniquetol 使用容差执行比较.

语法很简单:

<块引用>

C = uniquetol(A,TOL) 使用容差 TOL 返回 A 中的唯一值.

语义是:

<块引用>

C 的每个值都在 A 的一个值的容差范围内,但 C 中没有两个元素在彼此的容差范围内.C 按升序排列.两个值 uv 在容差范围内,如果:
    abs(u-v) <= TOL*max(A(:),[],1)

它也可以操作ByRows",容差可以通过输入DataScale"而不是输入数据中的最大值进行缩放.>

但是有一个关于解决方案唯一性的重要说明:

<块引用>

可以有多个有效的 C 输出满足条件,C 中没有两个元素在彼此的容差范围内."例如,交换 A 中的列可能会导致返回不同的解决方案,因为输入是按列按字典顺序排序的.另一个结果是 uniquetol(-A,TOL) 可能给出与 -uniquetol(A,TOL) 不同的结果.

还有一个新函数 ismembertolismember 的关联方式与上述相同.

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 it-- in double precision, we always have to compare two elements within a precision. Is there a built-in command that returns unique elements, within a certain tolerance?

解决方案

As of R2015a, there is finally a function to do this, uniquetol (before R2015a, see my other answer):

uniquetol Set unique within a tolerance.

    uniquetol is similar to unique. Whereas unique performs exact comparisons, uniquetol performs comparisons using a tolerance.

The syntax is straightforward:

C = uniquetol(A,TOL) returns the unique values in A using tolerance TOL.

As are the semantics:

Each value of C is within tolerance of one value of A, but no two elements in C are within tolerance of each other. C is sorted in ascending order. Two values u and v are within tolerance if:
    abs(u-v) <= TOL*max(A(:),[],1)

It can also operate "ByRows", and the tolerance can be scaled by an input "DataScale" rather than by the maximum value in the input data.

But there is an important note about uniqueness of the solutions:

There can be multiple valid C outputs that satisfy the condition, "no two elements in C are within tolerance of each other." For example, swapping columns in A can result in a different solution being returned, because the input is sorted lexicographically by the columns. Another result is that uniquetol(-A,TOL) may not give the same results as -uniquetol(A,TOL).

There is also a new function ismembertol is related to ismember in the same way as above.

这篇关于返回具有容差的唯一元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆