Operators in MATLAB

Operators

MATLAB has two different types of operators. Matrix operations are defined by the rules of linear algebra, while array operations can be performed element-wise and can be used for multidimensional arrays. The dot (.) character is used to distinguish array operations from matrix operations. For example, A*B represents traditional matrix multiplication, while A.*B represents array multiplication, where the product is an array of the same size as A and B, with each element being the product of the corresponding elements in A and B. In other words, if C=A.*B, then C(I,J)=A(I,J)*B(I,J). Since matrix operations and array operations are the same for addition and subtraction, the dot character is not used for + and -.

When writing an expression like B=A, MATLAB makes a “record” of B equal to A, but does not actually copy the data from A to B unless A’s contents change later in the program. This is important because using different variables to “store” the same content can sometimes enhance the clarity and readability of the code. Therefore, when writing MATLAB code, unless absolutely necessary, keep in mind that MATLAB does not copy information.

Operators in MATLAB

It is important to understand the differences between array and matrix operations; for example, consider the following operations:

Operators in MATLAB

For the array multiplication of A and B, the result is as follows:

Operators in MATLAB

Whereas matrix multiplication gives the familiar result:

Operators in MATLAB

Most arithmetic, relational, and logical operations involving images are array operations.

End

Leave a Comment