How do I replace a maximum value with zero?

20 visualizaciones (últimos 30 días)
Bridgit Nata
Bridgit Nata el 6 de Oct. de 2016
Comentada: Bridgit Nata el 19 de Oct. de 2016
Hi, if I have a m-by-n matrix how do I set the maximum value of the matrix to zero? Thank you!

Respuesta aceptada

James Tursa
James Tursa el 6 de Oct. de 2016
A = your matrix
A(A==max(A(:))) = 0;
  2 comentarios
Walter Roberson
Walter Roberson el 6 de Oct. de 2016
In my experience, people who ask this question are often wanting to find the top several maxima, and intent to proceed by finding the maximum, setting the location to a marker value that is not the maximum, then finding the maximum of the result and setting it to a marker value, and so on, until the desired number of maxima have been found.
One problem an approach such as that can run into is that the marker value they use might end up being larger than a maximum to be found, so they might end up starting to find the marker value instead of the actual maximum. For example, the approach of setting the maximum to 0 fails if you need to find the two largest maxima of [-2 7 -5]
Bridgit Nata
Bridgit Nata el 19 de Oct. de 2016
Thank you so much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by