在排序的向量中找到上限索引 [英] Find upper bound index in sorted vector
本文介绍了在排序的向量中找到上限索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Matlab中有一个像下面这样的向量.
I have a vector like the following in Matlab.
Columns 1 through 4
0.160000000000000 0.208000000000000 0.244000000000000 0.268000000000000
Column 5
0.280000000000000
我想找到以下值的上限索引:
And I want to find the upper bound index of the following value:
0.16230400000000
我知道该值在1°和2°索引之间,但是我想找到在这种情况下为索引2的上限,即使最接近的值在索引1处.我如何在Matlab中获得该值没有循环?
I know this value is between the 1° and 2° indices, but I want to find the upper bound which in this case is index 2, even when the closest value is at index 1. How do I get that in Matlab without a loop?
我找到了以下方法来找到最接近的值,但我始终需要上限.
I found the following method to find the closest value but I need always the upper bound.
[c ind] = min(abs(probCum-codComp));
推荐答案
如果您的数组以升序排序,则find命令特别强大:
If your array is sorted in an ascending fashion, the find command is especially powerful:
find (a>0.162,1)
这篇关于在排序的向量中找到上限索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文