如何找到给定数组 A1 的索引,其值的 *any* 实际上等同于第二个数组 A2 的值的 *any*? [英] How do I find the indices of a given array A1, *any* of whose values are practically equivalent to *any* of the values of a second array A2?
本文介绍了如何找到给定数组 A1 的索引,其值的 *any* 实际上等同于第二个数组 A2 的值的 *any*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过实际上等效",我的意思是它们的距离为 epsilon(或 0.000001).MATLAB 中的相等性通常不适用于长浮点数.
By "practically equivalent", I mean that their distances are of order epsilon apart (or 0.000001). Equality in MATLAB often doesn't really work for long floating numbers.
如果我只是做 abs(A1 - A2) <0.000001,它不会工作,因为 size(A1) != size(A2)
If I simply do abs(A1 - A2) < 0.000001, it's not going to work since size(A1) != size(A2)
推荐答案
您可以通过使用 MATLAB 的 pdist2
函数计算两个向量之间的距离来获得答案.
You can get the answer by calculating distance between two vectors using MATLAB's pdist2
function.
dist=pdist2(A1,A2);
minDist=min(dist,[],2);
indices_A1=minDist<=0.000001;
desired_A1=A1(indices_A1);
未经测试,但应该可以工作.
Not tested, but should work.
这篇关于如何找到给定数组 A1 的索引,其值的 *any* 实际上等同于第二个数组 A2 的值的 *any*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文