开发者

How to find all minimum elements in a vector

开发者 https://www.devze.com 2023-02-14 04:40 出处:网络
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 e

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

0

精彩评论

暂无评论...
验证码 换一张
取 消