Reputation: 531
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
.
Upvotes: 1
Views: 254
Reputation: 18858
You can use imreginalmin
as well with time complexity O(n)
:
largestMinIndex = find(imregionalmin(A),1,'last');
Upvotes: 2
Reputation: 26275
Here's a different idea, which only requires one function, sort:
[~,y] = sort(a,'descend');
i = y(end)
ans =
9
Upvotes: 3
Reputation: 289
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.
Upvotes: 3