How to write an if statement that returns which of the conditions is met
조회 수: 1 (최근 30일)
이전 댓글 표시
I have the following psuedocode:
if (cond1) or (cond2)
print('1');
end
Now I would like it to tell which of the two conditions are met or both of them are met by printing the corresponding conditions. How would I accomplish this?
댓글 수: 0
채택된 답변
Walter Roberson
2018년 1월 23일
Provided cond1 and cond2 are scalar logical values:
(cond1) + 2 * (cond2)
This returns 1 if cond1 but not cond2, returns 2 if cond2 but not cond1, and returns 3 if both of them are true.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Computations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!