How to find all minimum elements in a vector

后端 未结 2 1252
太阳男子
太阳男子 2021-01-22 09:08

In Matlab, by the function min(), I can only get one single minimum element of a vector, even if there can be several equal minimum elements. I was wondering how to get the indi

相关标签:
2条回答
  • 2021-01-22 09:19
    v = [1 2 3 1 5];
    find( v == min(v) )
    
    ans = 1 4
    

    At least in Octave (don't have matlab), this returns the indexes of all minimums in v

    0 讨论(0)
  • 2021-01-22 09:20

    You can use find to find the min values:

    find(v == min(v))
    
    0 讨论(0)
提交回复
热议问题