Programming and Data Types | ![]() ![]() |
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:
.'
), power(.^
), complex conjugate transpose('), matrix power(^
)
+
), unary minus (-
), logical negation (~
)
.*
), right division (./
), left division(.\
), matrix multiplication (*
), matrix right division (/
), matrix left division (\
)
-
)
:
)
<
), less than or equal to (<=
), greater than (>
), greater than or equal to (>=
), equal to (==
), not equal to (~=
)
&
)
|
)
Overriding Default Precedence
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
Expressions can also include values that you access through subscripts.
b = sqrt(A(2)) + 2*
B(1)
b =
7
![]() | Logical Operators | Flow Control | ![]() |