Sum(X) = 1 but Sum(X)==1 produces logical 0
Show older comments
Can someone please explain this?
sum([Node(temp).pbelief])
ans =
1.0000
K>> sum([Node(temp).pbelief])==1
ans =
0
By the way:
Node(temp(1)).pbelief
ans =
0.0024
K>> Node(temp(2)).pbelief
ans =
0.9976
Accepted Answer
More Answers (2)
James Tursa
on 22 Jul 2014
Note that when a number is exactly an integer, and you are only printing one scalar value, MATLAB prints it without any trailing 0's. But if the number is not exactly an integer, MATLAB will print trailing 0's, indicating that there is a non-zero digit down the line somewhere even if it is not printed to the screen. E.g.,
>> format short
>> 1
ans =
1
>> 1.0000001
ans =
1.0000
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!