drosophilia
2009-05-28, 15:10
Matlab中的逻辑运算"&&"与"&","||"与"|"的区别是怎么样的?
& 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.
望有帮助!!!
vBulletin® v3.8.3,版权所有 ©2000-2025,Jelsoft Enterprises Ltd.