Finding 2nd minimum value in an array

44 views (last 30 days)
I want to find the 2nd minimum value in an array. min(A) can be used to find the minimum value, but I want to find the the number greater than minimum (2nd minimum). Can anyone help me in doing that???

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 3 May 2012
A2 = sort(A(:));
out = A2(2);
other way:
A2 = unique(A(:));
out = A2(2);
or:
out = min(setdiff(A(:),min(A(:))));
etc.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!