登录论坛

查看完整版本 : [MATLAB基础] Matlab中的逻辑运算"&&"与"&","||"与"|"的区别


drosophilia
2009-05-28, 15:10
Matlab中的逻辑运算"&&"与"&","||"与"|"的区别是怎么样的?

TTT_IOU
2009-05-29, 23:43
& Element-wise Logical AND.
A & B is a matrix whose elements are logical 1 (TRUE) where both A
and B have non-zero elements, and logical 0 (FALSE) where either has
a zero element. A and B must have the same dimensions (or one can
be a scalar).

&& Short-Circuit Logical AND.
A && B is a scalar value that is the logical AND of scalar A and B.
This is a "short-circuit" operation in that MATLAB evaluates B only
if the result is not fully determined by A. For example, if A equals
0, then the entire expression evaluates to logical 0 (FALSE), regard-
less of the value of B. Under these circumstances, there is no need
to evaluate B because the result is already known.

| Element-wise Logical OR.
A | B is a matrix whose elements are logical 1 (TRUE) where either
A or B has a non-zero element, and logical 0 (FALSE) where both have
zero elements. A and B must have the same dimensions (or one can
be a scalar).

|| Short-Circuit Logical OR.
A || B is a scalar value that is the logical OR of scalar A and B.
This is a "short-circuit" operation in that MATLAB evaluates B only
if the result is not fully determined by A. For example, if A equals
1, then the entire expression evaluates to logical 1 (TRUE), regard-
less of the value of B. Under these circumstances, there is no need
to evaluate B because the result is already known.
望有帮助!!!