Replacing the minimum of a vector
Show older comments
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.
Accepted Answer
More Answers (1)
Alan Stevens
on 27 Aug 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 Comment
Kalista Hall
on 27 Aug 2020
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!