I want to get the 2nd minimum number from a matrix. Elements in matrix are random and i don't want to sort them. for example
A=[2 6 83 14 29;17 42 31 90 23;17 52 43 81 29;48 11 90 21 58];

답변 (2개)

Jeremy
Jeremy 2015년 1월 29일

1 개 추천

It is a little cumbersome but for any array x, this should work:
min(x(x~=min(x(:))))
Guillaume
Guillaume 2015년 1월 29일

0 개 추천

I don't want to sort them.
Asking for the nth element is by definition sorting them.
One possible way (which obviously does a sort):
A = [2 6 83 14 29;17 42 31 90 23;17 52 43 81 29;48 11 90 21 58];
u = unique(A);
a2 = u(2) %achtung baby!

댓글 수: 2

its not giving correct result.
Guillaume
Guillaume 2015년 1월 29일
Huh! And what is the 'correct result' you expect?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

질문:

2015년 1월 29일

댓글:

2015년 1월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by