简体   繁体   English

如何找到最小索引?

[英]How to find the minimum index?

I have vector a=[7;4;3;2;5;6;2] of length 7 and the element 2 is the minimum element, but there are two locations of where the minimum is.我有长度为 7 的向量a=[7;4;3;2;5;6;2]并且元素 2 是最小元素,但有两个位置是最小值。

I need to find the smallest position of the minimum element.我需要找到最小元素的最小位置。 How can this be done in MATLAB?这如何在 MATLAB 中完成?

Use the second output of min .使用min的第二个输出。 It gives you the location of where the minimum was found.它为您提供了找到最小值的位置。 In the case of there being more than one element being the minimum, the location returned is the first one found, corresponding to the smallest location:在有多个元素为最小值的情况下,返回的位置为找到的第一个,对应最小的位置:

>> a=[7;4;3;2;5;6;2];
>> [~,ind] = min(a);
>> ind

ind =

     4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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