how to select the second maximum value for an array.

回答 (2 件)

ES
ES 2020 年 1 月 7 日

0 投票

B = sort(A, 'descend');
Max2 = B(2);
Lucademicus
Lucademicus 2020 年 1 月 7 日

0 投票

One way would be to sort the array and take the value of the second to last value.
[a,b] = sort(A);
maximum = A(b(end-1));
There are multiple ways to achieve this. I'm sure somebody will come up with a nicer oneliner, but this should do your job.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2020 年 1 月 7 日

コメント済み:

2020 年 1 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by