About logical calculation. Is this a bug?

조회 수: 13 (최근 30일)
Jingli Xie
Jingli Xie 2020년 1월 14일
댓글: Steven Lord 2020년 1월 14일
3.jpg
what happened to this case? Is this a matlab bug?
  댓글 수: 1
Jingli Xie
Jingli Xie 2020년 1월 14일
logical should be 1 at the lower left corner of the picture.
-1<p_grad == 1, p_grad < 1 ==1, bug -1<p_grad<1 == 0

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 1월 14일
편집: Adam Danz 2020년 1월 14일
The operation
p_grad = 1.1200e-17;
-1 < p_grad < 1
works from left-to-right. It is interpretted as
p_grad = 1.1200e-17;
(-1 < p_grad) < 1
which is simplified to
1 < 1
which equals 0 (false).
To determine if p_grad is between -1 and 1, (parentheses optional)
(-1 < p_grad) && (p_grad < 1) % for scalar values
(-1 < p_grad) & (p_grad < 1) % for non-scalar values or when
% number of element is unknown
  댓글 수: 3
Steven Lord
Steven Lord 2020년 1월 14일
If I remember correctly, as of release R2019b if you try to use that idiom in a file in the Editor Code Analyzer will warn you that it doesn't do what you think it does.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by