MATLAB Operator Precedence - dummies

MATLAB Operator Precedence

By Jim Sizemore, John Paul Mueller

Part of MATLAB For Dummies Cheat Sheet

Knowing the order in which tasks are performed is essential. Otherwise, the formulas you type won’t work as expected and you’ll obtain errant results. The following table shows the order in which MATLAB evaluates various operators.

You can also remember operator precedence using the PEMDAS acronym, which stands for Parentheses, Exponent, Multiply And Divide, Add and Subtract.

Operator Description
() Parentheses are used to group expressions and to override the
default precedence so that you can force an operation of lower
precedence (such as addition) to take precedence over an operation
of higher precedence (such as multiplication).
. .^ ^ Transpose, power, complex conjugate transpose, matrix
+ – ~ Unary operators interact with a single variable or
.* ./ . * / Multiplication and division(both right and left).
+ – Addition and subtraction.
: Colon operator (used for ranges).
<= < > >= Comparison operators.
== ~= Equality operators.
& | Logical operators (element-wise).
&& || Logical operators (short-circuit).