if statements using logical operators
조회 수: 10 (최근 30일)
이전 댓글 표시
Let me define first that: 'distance' is a vector (1 x n) and 'f' is a scalar (1 x 1). Example: distance = [1 10 5]; f = 2. The logical operator: distance > 2 would output: [0 1 1].
I want to say that if the output is NOT all zero, then do X. If the output is all zero, then do Y. How do I translate that to if-then statements?
Thanks for your help.
댓글 수: 0
채택된 답변
Star Strider
2015년 11월 6일
One approach:
if all(distance > f)
sprintf('All distances > %.1f',f)
else
sprintf('Some distances <= %.1f',f)
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!