Replacing the minimum of a vector
Mostrar comentarios más antiguos
Hi
So I'm trying to replace the minimum value of a vector to infinity but when I test it, it's not usually the minimum value that gets replaced. It seems random, but that doesn't make sense.
x=input('Enter a vector for x');
x(min(x))=inf
I tried with [8,3,6,4] and it replaced the 6.
I tried with [7,3,5,2] and it replaced the 3.
I tried with [2,3,6,1] and it replaced the 2.
I have no idea where I'm going wrong. Anyone have any ideas? I'd really appreciate it.
Respuesta aceptada
Más respuestas (1)
Alan Stevens
el 27 de Ag. de 2020
In your first one the minium value of x is 3, so Matlab replaced the third element with inf. Similar comments apply to the other examples. Try
x(x==min(x)) = inf;
instead.
1 comentario
Kalista Hall
el 27 de Ag. de 2020
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!