Replacing the minimum of a vector
古いコメントを表示
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.
採用された回答
その他の回答 (1 件)
Alan Stevens
2020 年 8 月 27 日
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.
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!