Assigning value to an element in vector
2 次查看(过去 30 天)
显示 更早的评论
The problem is trivial but the code does not work. I wanted to replace 1 by -1 in a matrix
ip = [0 1 1 0;0 0 0 1]
X=find(ip == 1)
for i=1:length(X)
ip(X(i))=-1
end
But this does not work and is beyond my understanding. Is there any logical error here?
1 个评论
Azzi Abdelmalek
2013-9-4
编辑:Azzi Abdelmalek
2013-9-4
Your code is correct
Is there any error message? If not what is the result?
回答(1 个)
Walter Roberson
2013-9-4
Runs correctly for me.
In your actual code, is it possible that what you really have for "1" is not an integer? For example if you were searching for 1.3 ? If so then
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!