Hi ;
I have a code in which
function metCondition = Ambient_Temperature(vector)
metCondition = true; % Initialize
if any((vector) <= -7 | (vector) >= 37.86) %degC
metCondition = false;
end
what is the difference between
if any((vector) <= -7 | (vector) >= 37.86) %degC
and
if any((vector) <= -7 || (vector) >= 37.86) %degC
and why am i getting an error when using ||.
Thanks

 채택된 답변

James Tursa
James Tursa 2017년 1월 11일
편집: Stephen23 2017년 1월 12일

0 개 추천

The "|" operator is an element-wise operator, intended to be used on arrays element-by-element. The "||" operator is a short-circuiting operator restricted to be used on scalars only. See the doc:
For your case, you clearly want the | operator.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 1월 11일

1 개 추천

You could use
if any((vector) <= -7) || any((vector) >= 37.86) %degC
|| can only be used when both sides return scalars. || is the "short circuit" OR operator -- it does not bother evaluating the right hand side of the left hand side is already true.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2017년 1월 11일

편집:

2017년 1월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by