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

1 visualización (últimos 30 días)
Serhii Sheinych
Serhii Sheinych el 22 de Nov. de 2019
Comentada: Walter Roberson el 23 de Nov. de 2019
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?

Respuesta aceptada

Bryan
Bryan el 22 de Nov. de 2019
Editada: Bryan el 22 de Nov. de 2019
another option would be
max(a(a<max(a)))
  4 comentarios
Bryan
Bryan el 23 de Nov. de 2019
Editada: Bryan el 23 de Nov. de 2019
Yes, I agree. Use Walter Roberson's solution.
Walter Roberson
Walter Roberson el 23 de Nov. de 2019
They are both valid, just slightly different on edge cases.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 22 de Nov. de 2019

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by