How to print the second largest of a group of the numbers

답변 (2개)

Mischa Kim
Mischa Kim 2014년 10월 6일
Rodrigo, you could use
a = [1 2 3 4 5 6 7 8 9 10];
b = max(setxor(a,max(a)));
Guillaume
Guillaume 2014년 10월 6일
편집: Guillaume 2014년 10월 6일
Another option (which also allows you to pick any nth largest number):
a = [1 2 3 4 5 6 7 8 9 10];
ua = unique(a); %will sort a and remove duplicate
b = ua(end-1); %for the 2nd largest
b = ua(end-n+1); %for the nth largest

카테고리

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

질문:

2014년 10월 6일

편집:

2014년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by