How to find all minimum elements in a vector
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 indices of all minimum elements in a vector?
For example,
v=[1,1];
I would like to get the indices 1 and 2, both of which index the smallest elements 1.
Thanks and r开发者_开发百科egards!
You can use find
to find the min values:
find(v == min(v))
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
精彩评论