How to find value which is berofe max value of an array?

1 回表示 (過去 30 日間)
Serhii Sheinych
Serhii Sheinych 2019 年 11 月 22 日
コメント済み: Walter Roberson 2019 年 11 月 23 日
I have an array, let it be r1 = rand(1,100).
I need to find max value and a value which is before maximum. How can i do it?
Maimum = max (r1);
p.s Simple example a = [1, 4, 10, 2, 7, 3, 6];
I know that max is 10, and 7 is before my max value. How to find 7, using Matlab?

採用された回答

Bryan
Bryan 2019 年 11 月 22 日
編集済み: Bryan 2019 年 11 月 22 日
another option would be
max(a(a<max(a)))
  4 件のコメント
Bryan
Bryan 2019 年 11 月 23 日
編集済み: Bryan 2019 年 11 月 23 日
Yes, I agree. Use Walter Roberson's solution.
Walter Roberson
Walter Roberson 2019 年 11 月 23 日
They are both valid, just slightly different on edge cases.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 11 月 22 日

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by