简体   繁体   中英

Find the largest index of the minimum in Matlab

I have an array of positive numbers and there are some duplicates. I want to find the largest index of the minimum value.

For example, if a=[2, 3, 1, 1, 4, 1, 3, 2, 1, 5, 5] then [i, v] = min(a) returns i=3 , however I want i=9 .

Using find and min .

A = [2, 3, 1, 1, 4, 1, 3, 2, 1, 5, 5];
minA = min(A);
maxIndex = max(find(A==minA));

min get the minimun value, and find return de index of values that meet the condition A==minA . max return de maximun index.

Here's a different idea, which only requires one function, sort :

[~,y] =  sort(a,'descend');
i = y(end)

ans =

     9

You can use imreginalmin as well with time complexity O(n) :

largestMinIndex = find(imregionalmin(A),1,'last');

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