如何阈值/过滤矢量? [英] how to threshold/filter a vector?
问题描述
我有一个包含数据列表(X和Y坐标)的向量,我想将其与100个向量(每个具有相似但不相同的XY坐标)的数组进行比较以找到匹配。 >
每个矢量的数据大小范围在10到20之间,这在匹配不同大小的矩阵时会引起问题。
所以为了匹配我已经使用matchfeatures匹配确切的数据,这是没有用的矢量不同大小。
所以我做
(使用pdist转电线到距离)
threshigh =(vector1 / 100)* 110;
threslow =(vector1 / 100)* 90;
if(Vector2< = threshigh)&&< vector2> = threslow
显示匹配
其他
不匹配
结束
这是完美的!但是..我不能使用矢量运算符,因为它们只适用于标量。
如何解决这个问题?
即使这样做,我也想到了这个范围内的某些值,如果不是这样,它就不会匹配?我怎样才能取得大部分的结果? 解决方案
重复问题的链接应该解决您的第一个问题。至于你的第二个问题:
...即使这个工作,并且矢量中的一些值落在这个范围之间,它将不匹配,除非他们都这样做?一旦你有一个逻辑数组(1的位置对应于元素的位置)指定的范围和其他地方的0),您可以按照自己的喜好来操作它。
在当前的表单中,
if $ c $只有 all 元素是
true
(逻辑'1'),c>语句才会分支。如果您知道被测试的表达式可能是一个向量(即 array ),您可以执行以下操作:
使用
任何
命令检查数组中是否至少有一个元素是true
:如果有的话(...)
%//做某事...
end
使用
all
命令检查是否所有元素都是true
:如果全部(...)
%//做某事...
结束
(使用
all
在这里是多余的,但确实增强了可读性...)
使用
mode
:
if mode(double ...))
%//做一些事情...
end
mode
返回数组中最频繁的元素,所以如果它是'1',那么如果
语句将会分支。
I have a vector containing a list of data (X and Y coords) which i want to compare to an array of 100 vectors (each with similar but not the same XY Coords) in order to find a match.
Each vector ranges in data size (between 10 and 20 cords) which causes issues when matching matrices of different sizes.
so in order to match i have used the matchfeatures which matches exact data which is no use as vectors different sizes.
so i made (using pdist to turn cords into distances)
threshigh = (vector1/100) * 110; threslow = (vector1/100) * 90; if (Vector2 <= threshigh)&&(vector2 >= threslow) disp its a match else not a match end
this is perfect! but.. I cannot use operators on vectors as they only apply to scalar quantities.
how do i get around this?
it has also occurred to me even if this works and some values in the vector fall between this range it will not match unless they all do? how do i just take majority of results?
解决方案The link of the duplicate question should solve your first problem. As for your second issue:
... even if this works and some values in the vector fall between this range it will not match unless they all do? how do i just take majority of results?
Once you have a logical array (with 1's at the positions corresponding to elements that fall within the specified range, and 0's elsewhere), you can manipulate it to your liking.
In its current form, the
if
statement branches only if all elements aretrue
(logical '1'). If you know that the tested expression might be a vector (that is, an array), you can do the following:
Use the
any
command to check if at least one element in the array istrue
:if any(...) %// Do something... end
Use the
all
command to check if all elements aretrue
:if all(...) %// Do something... end
(using
all
here is superfluous, but it does enhance readability...)Check for a majority of '1's by using
mode
:if mode(double(...)) %// Do something... end
mode
returns the most frequent element in the array, so if it's '1' theif
statement will branch.这篇关于如何阈值/过滤矢量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!