Matlab Minimum

Hello,
If I have an array for example: A=[10 11 12 1 8 9 1 3 5] and I use the '[C,I]=min' function to find the minimum value of the array. But if the array has two or more same minimum values, the MIN function always return the first value!How can I get the last minimum value of an array?In my example, I want the 7th value 1 of array A and not the 4th.However, I want this function to work for random arrays and not only for array A.
Thank you..!!

 采纳的回答

Matt Tearle
Matt Tearle 2011-3-3
find(A==min(A))
will get them all. Then you can choose whichever you like. To get just the last one
find(A==min(A),1,'last')

3 个评论

when I use this function, returns the indexes of both minimums (4, 7). How can I return only the last (7)? But I want this function for random arrays and not only for my example!
I haven't seen your complete answer!Thank you..!!!:)
Excellent! Didn't new that one.

请先登录,再进行评论。

更多回答(2 个)

Andreas Goser
Andreas Goser 2011-3-3

0 个投票

My rough idea is along the lines of sorting the vector first (with saving the indices) and then identify the last minimum.
David Young
David Young 2011-3-3
If you only want the last one, you could use
[v, ind] = min(A(end:-1:1));
ind = 1 + length(A) - ind;

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by