How do I find the Nth high number in a matrix A ?

20 ビュー (過去 30 日間)
Victor Noronha
Victor Noronha 2014 年 9 月 25 日
編集済み: Stephen23 2014 年 9 月 25 日
Hi guys,
I need to find the 5th high number of a matrix. Using the max() function I can only have the 1st one.
Thanks for helping!

採用された回答

Stephen23
Stephen23 2014 年 9 月 25 日
編集済み: Stephen23 2014 年 9 月 25 日
As Iain suggested, sort is a great way to go, but as you mention that you have a matrix, you might want to sort every element of the matrix:
sorted = sort(values(:));
sorted(end-4)

その他の回答 (2 件)

Iain
Iain 2014 年 9 月 25 日
values = 1:500;
sorted = sort(values,'descend');
sorted(5)

José-Luis
José-Luis 2014 年 9 月 25 日
If you want to take care of repeated values:
vals = randi(200,10);
uVals = sort( unique(vals(:)) );
result = uVals(end-4);

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by