라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.
## Operator Precedence

### Precedence of AND and OR Operators

### Overriding Default Precedence

## More About

You
can build expressions that use any combination of arithmetic, relational,
and logical operators. Precedence levels determine the order in which MATLAB^{®} evaluates
an expression. Within each precedence level, operators have equal
precedence and are evaluated from left to right. The precedence rules
for MATLAB operators are shown in this list, ordered from highest
precedence level to lowest precedence level:

Parentheses

`()`

Transpose

`(.')`

, power`(.^)`

, complex conjugate transpose`(')`

, matrix power`(^)`

Power with unary minus

`(.^-)`

, unary plus`(.^+)`

, or logical negation`(.^~)`

as well as matrix power with unary minus`(^-)`

, unary plus`(^+)`

, or logical negation`(^~)`

.**Note:**Although most operators work from left to right, the operators`(^-)`

,`(.^-)`

,`(^+)`

,`(.^+)`

,`(^~)`

, and`(.^~)`

work from second from the right to left. It is recommended that you use parentheses to explicitly specify the intended precedence of statements containing these operator combinations.Unary plus

`(+)`

, unary minus`(-)`

, logical negation`(~)`

Multiplication

`(.*)`

, right division`(./)`

, left division`(.\)`

, matrix multiplication`(*)`

, matrix right division`(/)`

, matrix left division`(\)`

Addition

`(+)`

, subtraction`(-)`

Colon operator

`(:)`

Less than

`(<)`

, less than or equal to`(<=)`

, greater than`(>)`

, greater than or equal to`(>=)`

, equal to`(==)`

, not equal to`(~=)`

Element-wise AND

`(&)`

Element-wise OR

`(|)`

Short-circuit AND

`(&&)`

Short-circuit OR

`(||)`

MATLAB always gives the `&`

operator
precedence over the `|`

operator. Although MATLAB typically
evaluates expressions from left to right, the expression `a|b&c`

is
evaluated as `a|(b&c)`

. It is a good idea to
use parentheses to explicitly specify the intended precedence of statements
containing combinations of `&`

and `|`

.

The same precedence rule holds true for the `&&`

and `||`

operators.

The default precedence can be overridden using parentheses, as shown in this example:

A = [3 9 5]; B = [2 1 5]; C = A./B.^2 C = 0.7500 9.0000 0.2000 C = (A./B).^2 C = 2.2500 81.0000 1.0000

Was this topic helpful?