# MATLAB Operators and Symbols: Types and Uses

MATLAB - short form for “Matrix Laboratory” is a rich programming language. MATLAB programming finds its use in diverse applications, including numerical calculations, mathematical modeling, and complex simulations. In simple terms, MATLAB operators are character symbols that perform certain actions on their operands.

MATLAB is not limited to matrix operations or array operations; in fact, MATLAB also works with scalars.

MATLAB Operators and Symbols: Types and Uses

For those looking to achieve MATLAB assignment mastery, CWAssignments offers specialized support that significantly enhances learning outcomes and project completion efficiency. This platform is a go-to for students and professionals aiming to deepen their understanding of MATLAB's functionalities and apply them effectively in their work.

## Understanding Arithmetic Operators in MATLAB

MATLAB is very rich in arithmetic operators. It has arithmetic operators that work with scalars and some special arithmetic operators for matrix operations and array operations.

Arithmetic operators function according to the PEMDAS acronym, i.e., Parentheses, Exponent, Multiply, Divide, Add, and Subtract. In MATLAB programming, generally, arithmetic operators are evaluated from left to right.

Symbols

Description

+

Addition operator – works similarly on scalars, arrays, and matrices (element-wise addition)

-

Subtraction operator – works similarly on scalars, arrays, and matrices (element-wise addition)

*

Multiplication operator – for arrays and matrices, the columns of the first operand must be equal to the rows of the second.

.*

Element wise multiplication operator – especially for matrices and arrays. Works when the size of both operands is the same.

.^

Element wise power operator – especially for matrices and arrays. Matrix powered matrix. Works when the size of both operands is the same.

.\

Element-wise array left division – especially for matrices and arrays. Divides left operand by right element-wise. The size of operands must be the same.

\

Regular left division – Performs matrix inversion, i.e., X=A-1B. Notice that the inverted matrix is on the left.

./

Element-wise array right division – especially for matrices and arrays. Divides right operand by left element-wise. The size of operands must be the same.

/

Regular right division – Performs matrix inversion, i.e., X=BA-1. Notice that the inverted matrix is on the right.

## The Role of Relational Operators in MATLAB

Relational operators are MATLAB operators used for logical decision-making based on the relation between operands. The result of relational operators is either a logical true (1) or false (0). Some relational operator functionalities are mentioned below.

Symbols

Description

>

Checks if left operand is greater than the right operand

>=

Checks if left operand is greater than or equal to the right operand

<

Checks if left operand is less than the right operand

<=

Checks if left operand is less than or equal to the the right operand

==

Checks if left and right operands are equal

~=

Checks if left and right operands are not equal

## Logical and Bitwise Operators: Enhancing MATLAB Operations

In MATLAB programming, logical operators perform logical operations, e.g., AND, OR, NAND, and NOT on scalars and vectors. Logical operators’ functionalities are listed below:

Symbols

Description

&&

AND logical operator – Works with logical scalar values

&

Element wise AND Operator – Works with logical arrays and matrices if the size of operands matches. Also serves as a bitwise operator.

||

OR logical operator – Works with logical scalar values

|

Element wise OR Operator – Works with logical arrays and matrices if the size of operands match. Also serves as a bitwise operator.

~

NOT logical operator – It operates on a single operand and negates its state

Let’s differentiate between bitwise operators and logical operators by an example. In Figure 1, it is clear that ‘&&’ does not work with a logical array because it is a logical operator and not a bitwise operator.

## Exploring Set Operators in MATLAB Programming

Set operators in MATLAB operate on vectors and arrays to form new sets. Assume A & B are two sets (vectors in MATLAB). Some MATLAB set operator functionalities are mentioned next:

Symbols

Description

union(A,B)

Enhancement: Combines unique elements of two sets to form a new set

intersect(A,B)

Enhancement: Retrieves common elements from two sets

setdiff(A,B)

Enhancement: Equivalent to set operation A-B. Retrieves elements of A that are not in B

Ismember(A,B)

Enhancement: If A-B = A, it returns an array of 1’s with a size equal to that of A.

### Differences Between Matrix and Array Operators

To differentiate between matrix operations and array operations in MATLAB programming, it is useful to understand the difference between matrix and array. Matrix operations work according to algebra rules, whereas array operations are element-wise operations.

-A dot before the arithmetic operator differentiates array operators from matrix operators. Let’s understand this with the help of an example.

Figure 2 defines two matrices. The result of bitwise multiplication produces a valid result. However, the algebraic multiplication throws an error as the number of columns in A is unequal to rows in B. Note the ‘.’ before * for the array operation.

### Practical Applications of MATLAB Operators

MATLAB programming finds its applications in almost every discipline of research and computing. The simple MATLAB operators perform critical functions in high-level projects. Digital image processing is an ideal application of MATLAB operators.

Digital images are actually matrices, and any modification to the image requires manipulating the matrix using MATLAB operators.

Quantum computing and control systems are two more prime applications of MATLAB programming. In both cases, matrices, arrays, or vectors save the states of the system. To manipulate the states, MATLAB operators are very frequently used.

### MATLAB Operators: Tips and Tricks for Efficient Coding

In the context of MATLAB operators, rather than using loops in MATLAB programming, use matrix and vector MATLAB operators. Using a loop for indexing consumes more time and memory. MATLAB programming language defines the concept of vectorization: performing operation on all matrix elements at once.

Vectorization significantly increases code efficiency and readability. Similarly, instead of loops, using logical indexing for retrieving array or matrix elements saves time and memory.

In MATLAB programming, short-circuit evaluation is a mechanism where in a logical expression, the second operand needs not to be evaluated if the result can be determined by the first operand alone. This obviously saves time and increases speed. The MATLAB operators ‘&&’ and ‘||’ follow a short-circuit mechanism.