Operators is a fundamental element of Matlab that you’ll need to be familiar with when learning and working with Matlab. In this article, we cover everything you’d want to know about Matlab operators – what are Matlab operators and their different types.

#### Data Science Career Boot Camp

The Ultimate Ticket to Top Data Science Job Roles ## What Are Matlab Operators?

In computer programming and mathematics, the term operator refers to a symbol used to perform specific logical and mathematical operations. It can also be defined as a character that represents an action. For example, the - sign refers to the operation subtraction, while the symbol + refers to the operation of addition. These symbols in common are called operators.

Matlab deals with different variables, functions, and arithmetic operations using several operators, symbols, and special characters. Matlab operates on whole arrays and matrices hence, Matlab functions work on non-scalar and scalar data.

## Different Types of Operators

There are different types of Matlab operators.

• Arithmetic operators
• Relational operators
• Logical operators
• Bitwise operators
• Set operators

### 1. Arithmetic Operators

There are two types of Arithmetic operators in Matlab. They are –

• Matrix arithmetic operators
• Array arithmetic operators

If the Arithmetic operator is used with one or more operands as arrays, then it is called Array arithmetic operators. If we use the Arithmetic operator with one or more operands as a matrix, it is called a matrix arithmetic operator. What differentiates the array arithmetic operator from the matrix arithmetic operator is that in the case of the array arithmetic operator, we will use a (.).

As the name suggests, this operator performs the function of adding two values. The condition for adding two values is that both the values have to be the same size. If not, one of them has to be a scalar value.

#### Subtraction Operator (-)

As the name suggests, this operator performs the function of subtracting one value from the other. In this case, both values have to be the same size. If not, one of them has to be a scalar.

#### Matrix Multiplication

C is considered the linear algebraic product of A and B if C= A*B. The condition for this to occur is if the number of columns in A is equal to the number of columns in B and if both the operands are non-scalar.

#### Array Multiplication(.*)

This operator performs the function of multiplying element of each operand with the other. So, given that A and B are the same size,  C= A.*B.

#### Matrix Right Division (/)

For instance, when B and A are two matrices, B/A and B*inv(A) are nearly equivalent.

#### Data Scientist Master's Program

In Collaboration with IBM #### Array Right Division (./)

The sole distinction is that in this instance, B./A will apply only if both A and B must be the same size unless one is scalar.

#### Matrix Left Division (\)

A is a by-n matrix, and B is a column vector in this particular sort of matrix multiplication.  X=A/B can be the solution to AX=B.

#### Array Left Division (.\)

In this, A.\B is the matrix with elements B(i,j) \a(I,j), given that A and B must have the same size.

#### Matrix Power(^)

X^p is X to the power p. If p is scalar or p is an integer, then the power is computed by repeated squaring.

#### Array Power (.^)

If both the matrices have the same size, then ^p is matrix X to the power matrix, given that both are scalar.

#### Matrix Transpose (‘)

In a matrix, A, A’ will be its linear algebraic transpose. If the matrix A is complex, then A’ will result in a  complex conjugate transpose.

#### Array Transpose (.’)

A.’ is the transpose of an array A. However, unlike the matrix transpose, there is no complex conjugate for the complex array A.

### 2. Relational Operators

A relational operator performs the function of finding the relation between each element and two arrays. If a relation exists, it returns the value as true or false. Depending on the outcome of an operation, the operator returns an array of the same size with the values true or false. These operators can work with both scalar data and non-scalar data.

• < refers to Less than
• <= refers to less than equal to
• > refers to greater than
• >= refers to greater than or equal to
• == refers to equal to
• ~= refers to not equal to

### 3. Logical Operators

As the name suggests, logical operators perform logical operations. The result is given in a Boolean state as true or false. Here, the numbers 1 and 0 are used respectively to denote true or false. There are two types of logical operators.

#### Element-wise

Logical operators that operate on elements of logical arrays are called element-wise operators. The symbols used to denote these operators are & (AND), |(OR) ~ (NOT)

#### Short-circuit

These operators can be used with scalar and logical operations. The logical short circuit operators AND and OR are represented by the symbols && and ||.

### 4. Bitwise Operators

It follows a bit-by-bit operation, as the name suggests. The symbols used in the bit-by-bit operation are  |, &, and ^: Given below is a truth table to represent the same.

 P Q P & Q P | Q P ^ Q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1

There are various functions for bitwise and, bitwise or, bitwise not operations and shift operation, etc, provided by Matlab. Let us take a look at the various bitwise operations.

Matlab provides the following bitwise operators:

• bit and (a,b) – Bitwise AND of integers a and b
• Bitmap (a) – Bitwise complement of a
• Bitget (a, pos) – Get bit at a specified position, in the array a
• Bitset (a, pos) – set bit at a specified location of a
• bitShift (a,k) – It is equivalent to get multiplied by 2k. So, if k is negative, it shifts right, and if k is positive, it shifts left.
• bitor(a, b) – Bit-wise XOR of integers a and b

#### Learn From The Best in The Data Science Business!

Caltech Data Science Bootcamp ### 5. Set Operators

There are various operators provided by Matlab. Some of them are union, intersection, etc. Here is a list of operators given by Matlab.

intersect(A & B): This operator can be used to intersect A and B. However, it returns the common values of A and B in a sorted order.

intersect(A & B, ‘rows’): What it returns are rows that are common to both A and B.

ismember(A, B): If all the elements of A are present in B, it returns an array of size A with 1; otherwise, it returns none.

Issorted(A): It returns 1 if the elements in the array are in a sorted order. It gives a 0 if they are not sorted.

• union: The union of two arrays is set.
• unique: provides distinct values for an array

## Matlab Special Characters

• @: called the At symbol, whose role is to function manage construction and reference, and call super-class methods.
• .: called period or dot, the role of which is as a decimal point, element-wise operations, structure field access, object property, or method specifier.
• …: called dot dot dot or ellipsis, the role of which is in line continuation
• ,: called comma, the role of which is a line separator.
• :: called colon, the role of which is vector creation, indexing, and loop iteration.
• ;: called semicolon, the role of which is to signify the end of a row, suppress output of code line
• (): called parenthesis, the role of which is operator precedence, function argument enclosure, indexing.
• [ ]: called square brackets, the role is array concatenation, array construction, empty matrix, array element deletion, and multiple output argument assignment.
• { }: called curly brackets, the role of which is cell array assignment and contents
• %: called percent, the role of which is comment and conversion specifier.
• %{ %}: called percent curly brackets, the role of which is to block comments.
• !: called exclamation point, the role of operating system command
• ? : called question mark, the role of metaclass for Matlab class.
• ‘ ‘: called single quotes, the role of which is character array constructor
• “ “: is called double quote, the role of which is to string constructor
•  N/A: called space character, the role of which is to be a separator
• ~: called Tilde, the role of which is to be logical NOT, argument placeholder
• =: called the equal sign, the role of which is to be the assignment.

### 1. What are operators in Matlab?

Operators are symbols that perform specific logical and mathematical operations.

### 2. How many types of operators are in Matlab?

There are five types of operators in Matlab: arithmetic, relational, logical, bitwise, and set operators.

### 3. What do three dots mean in Matlab?

3 dots in Matlab are called dot dot dot or ellipsis. Its role is to refer to line continuation.

### 4. What does == mean in Matlab?

It is a relational operator and refers to equal to.

### 5. What are Matlab commands?

The line of code that begins with >> is called commands in Matlab.

Our Data Scientist Master's Program covers core topics such as R, Python, Machine Learning, Tableau, Hadoop, and Spark. Get started on your journey today!

## Conclusion

Matlab operators are integral to learning Matlab and using Matlab operations to perform data analysis functions. If you’re interested to take a deep dive and learn more about Matlab operators, Simplilearn’s Data Scientist Master’s Program is an excellent course for you. This extensive course has been designed by leading industry experts and veterans and brought to you in collaboration with IBM. Register today to solidify your knowledge of Matlab and other key concepts that will advance your career in the field of data and analytics. Simplilearn