If Condition match but got the else statement ?
조회 수: 1 (최근 30일)
이전 댓글 표시
To put it simple my code similar to :
k=6
if(a/b<k) && (a/b>=0)
STATEMENT1
elseif(a/b>-k) && (a/b<0)
STATEMENT2
end
The problem is i got a/b = 0, so it should give me STATEMENT1 but i got STATEMENT 2, does anyone know how i can figure out my mistake?
댓글 수: 3
답변 (2개)
Walter Roberson
2013년 3월 27일
Try using the command
format long g
and then displaying a/b
It probably isn't really 0.
댓글 수: 0
Jan
2013년 3월 28일
Please read your question again and note, that Matlab does not perform any strange or magic actions. Then these two details:
1. if(a/b<k) && (a/b>=0)
2. The problem is i got a/b = 0, so it should give me STATEMENT1 but i got STATEMENT 2
imply, that either a/b<k is FALSE, or your assumption that a/b==0 is wrong. A third possibility is, that you did not save the M-file after editing, such that Matlab does not run the program you currently see in the editor.
There are no other solutions. Walter's suggestion to increase the displayed precision is exhaustive to identify the problems.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!