how to set elements in a matrix to infinite
Show older comments
I have a 10 by 10 matrix with only value 0 and 1 in it. I want to set to infinite for elements who have a value of 0 and are not diagonal. But for code below, those elements are set to 1 instead of infinite. Any help will be appreciated.
for i = 1:10
for j = 1:10
if(A(i,j) == 0 && i~=j)
A(i,j) = Inf;
end
end
end
1 Comment
TAB
on 9 Apr 2012
What is the type of "A".
Is it logical (boolean)?
Accepted Answer
More Answers (0)
Categories
Find more on Operating on Diagonal Matrices 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!