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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by