I want to compare three logics should I used && or || or any other way to do that ?????

조회 수: 1 (최근 30일)
I want to compare three logics should I used && or or any other way to do that ?????
  댓글 수: 5
Adam
Adam 2017년 2월 23일
Tags are meant to give useful keywords related to the problem so people with the right expertise can find them quickly.

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

채택된 답변

Jan
Jan 2017년 2월 20일
편집: Jan 2017년 2월 20일
The | operator acts like or(), while || requires scalar arguments:
a = 1
b = 0
A = false(1, 4);
B = true(1, 4);
or(a, b) % correct
a | b % correct, but this is faster:
a || b % correct and efficient
A || B % fail
or(A, B) % correct
A | B % correct
The same for &&. The || and && operator apply a short-curcuiting: If the first operand determines the output alread like in 0&&1, the second is not evaluated. This matters, if the operands are functions:
str = 'asd';
if length(str > 3) && str(4) == 'f' % Handles 'asd' correctly!
  댓글 수: 1
shane watson
shane watson 2017년 2월 23일
편집: shane watson 2017년 2월 23일
Thank you, Jan Simon. I was confused in problem as you have mentioned in 2nd example that what if I have three comparisons instead of two i.e for example(str > 3) && str(4)==f and also any third one so again I have to use &&||

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by