# MATLAB operators

What are operators ?

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Matlab is designed to operate primarily on whole matrices and arrays. Therefore, operators in Matlab work both on scalar and non-scalar data. Matlab allows the following types of elementary operations:

* *

##### Arithmetic

Addition (+), subtraction (-), multiplication (*), division (/), power (^)

MATLAB allows two different types of arithmetic operations

- Matrix arithmetic operations
- Array arithmetic operations

Matrix arithmetic operations are same as defined in linear algebra. Array operations are executed element by element, both on one-dimensional and multidimensional array. The matrix operators and array operators are differentiated by the period (.) symbol.

Use of Arithmetic operators:

2^2/(5^2 -1) + 1 >>3.5 use of arithmetic operators in array (Note: declaration of array will be discussed in next article ) A = [1 2 3] % a is a roe vector with three elements B = [3; 4; 5] % b is column vector with three elements C = [7 8 9]<br><br> D = A + B %Error using ==> plus matrix dimensions must be agree. You can not add a row vector to a column vector E = A.*C %You can multiply (or divide) the elements of two same-sized vectors term by term with the array operator .* or ./ E = 7 16 27

##### Relational

Value comparisons (>, <, >=, <=, ==, ~=)

Relational operators compare operands quantitatively, using operators like “less than”, “greater than”, and “not equal to.” The result of a relational comparison is a logical array indicating the locations where the relation is true.

##### Array comparison

Numeric array

The relational operators perform element-wise comparisons between two arrays. The arrays must have compatible sizes to facilitate the operation. Arrays with compatible sizes are implicitly expanded to be the same size during execution of the calculation. In the simplest cases, the two operands are arrays of the same size, or one is a scalar. For more information.

Results will be given in binary format i.e either one or zero (see example below)

A = [1 2 6; 8 10 12] = 1 2 6 8 10 12 B = [3 4 5; 9 9 9] = 3 4 5 9 9 9 A < B Result will be 1 1 0 1 0 0 Similarly, you can compare one of the arrays to a scalar. A < 9 Result will be 1 1 1 1 0 0 <span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1"></span><span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1"></span>

Empty Arrays

The relational operators work with arrays for which any dimension has size zero, as long as both arrays have compatible sizes. This means that if one array has a dimension size of zero, then the size of the corresponding dimension in the other array must be 1 or zero, and the size of that dimension in the output is zero.

A = ones(4,0); B = ones(4,1); A == B ans = Empty matrix: 4-by-0 However, expressions such as A == []

##### Logical

Use relational operators in conjunction with the logical operators A&B (AND), A|B (OR), xor(A,B)(XOR), and ~A(NOT), to string together more complex logical statements.

True or false (Boolean) conditions (AND, OR, NOR, XOR, NOT)

Set

Unions, intersection, set membership

Bit-wise

Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.

Hi,

Thanks for appreciations and valuable time. In near future our team is coming up with small videos that will make it more clear to our users.

Regards

Ramesh