简体   繁体   中英

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 regards!

您可以使用find查找最小值:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM