【问题标题】:MATLAB - how do I find the first index where value is greater than threshold [duplicate]MATLAB - 如何找到值大于阈值的第一个索引[重复]
【发布时间】:2011-08-12 22:27:16
【问题描述】:

可能重复:
Given a vector a=[1,2, 3.2, 4, 5] and an element x=3 In vector a, how to find the exact entry which is bigger than x?

假设 a[] 是一个排序向量。如何找到第一个(最小)索引 ix 使得 a(ix) > 阈值?

【问题讨论】:

    标签: matlab find


    【解决方案1】:
    ix = find(a>threshold,1);
    

    很确定这会起作用

    【讨论】:

    • 不,你没有。来自 Matlab 文档:I = FIND(X,K,'first') is the same as I = FIND(X,K). 如果你想反过来,你只需要指出'last'。
    • phonon 和 oli 都可以工作。
    • 哦,呵呵。当然。我没有看到,1。对此感到抱歉:)
    • @Phonon:是的,first 是不必要的。但我通常包含它以明确我的意图是什么。
    • 我同意。在你的函数调用中严格没有害处 = )
    【解决方案2】:
    ix = find(a > threshold, 1, 'first');
    

    【讨论】:

      【解决方案3】:

      为了它, 当且仅当 a 已排序时,您可以这样做:

      ix = sum(a<=threshold)+1;
      

      【讨论】:

      • 不完全直接和优雅,但非常创新;因此 +1 = )
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2011-11-09
      • 1970-01-01
      • 2019-12-20
      • 2019-02-10
      • 1970-01-01
      相关资源
      最近更新 更多