How can I find maximum before a certain element in my matrix
Mostrar comentarios más antiguos
For example B=[5 8 5 2 6 9 10] min(B)=2
I am looking for maximum point before min(B), which is 8 (not maximum of B elements, which is 10)
Respuesta aceptada
Más respuestas (2)
Star Strider
el 5 de Mayo de 2015
This works:
B = [5 8 5 2 6 9 10];
[~,ix] = min(B);
MaxBeforeMin = max(B(1:ix))
producing:
MaxBeforeMin =
8
The code searches for the index of the first value of the minium and returns it as ‘ix’. It then takes the maximum up to that index, and reports it as ‘MaxBeforeMin’.
1 comentario
Lily
el 5 de Mayo de 2015
Jos (10584)
el 5 de Mayo de 2015
Just for fun, as a one-liner:
B = [5 8 5 2 6 9 10];
MaxBeforeMin = max(B(1:find(B==min(B),1,'first')))
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!