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

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

问题描述

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

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?

推荐答案

从R2015a起,终于有了一个实现此功能的我的其他答案):

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

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

  < c1>与unique相似. unique执行精确比较,而uniquetol使用容差进行比较.

uniquetol Set unique within a tolerance.

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

语法很简单:

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

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

语义也是如此:

每个C值都在一个A值的公差范围内,但是C中没有两个元素在彼此的公差范围内. C以升序排序.如果满足以下条件,则两个值uv都在公差范围内:
    abs(u-v) <= TOL*max(A(:),[],1)

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)

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

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:

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

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).

还有一个新功能ismembertol以与上述相同的方式与ismember相关.

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

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

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