当前位置: 动力学知识库 > 问答 > 编程问答 >

matlab - How to find the third maximum value in matrix?

问题描述:

This question already has an answer here:

  • Find n minimum values in an array

    3 answers

网友答案:

The simplest solution would be to sort the values of A in descending order, and pick the third sorted element (if it exists):

A_sorted = sort(A(:), 'descend');
third_max = A_sorted(min(3, end));

If you don't allow repeating values (e.g A = [10, 10; 9; 2] and want 2), sort the unique values:

A_sorted = sort(unique(A), 'descend');
分享给朋友:
您可能感兴趣的文章:
随机阅读: