问题描述:

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');
相关阅读:
Top