How is a logical array evaluated as an if condition?

조회 수: 17 (최근 30일)
Guido Gervasio
Guido Gervasio 2017년 3월 17일
답변: Steven Lord 2017년 3월 17일
For example:
if logical([0, 0, 1)])
% code
end

채택된 답변

Steven Lord
Steven Lord 2017년 3월 17일
" if expression, statements, end evaluates an expression, and executes a group of statements when the expression is true. An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric). Otherwise, the expression is false."
Your vector logical([0 0 1]) is nonempty, but it does not contain only nonzero elements. So the expression is false and the body of your if statement is not executed.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by