如何找到一个给定数组A1的指数,*其值几乎相当于第二阵列A2值的* *任何任何*? [英] 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?

查看:82
本文介绍了如何找到一个给定数组A1的指数,*其值几乎相当于第二阵列A2值的* *任何任何*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过几乎等同,我的意思是,他们的距离是为了小量的分开(或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,它不会因为尺寸(A1)上班!=尺寸(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的指数,*其值几乎相当于第二阵列A2值的* *任何任何*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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