Replacing the minimum of a vector
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
Alan Stevens
le 27 Août 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 commentaire
Kalista Hall
le 27 Août 2020
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!