[matlab] What does operator "dot" (.) mean?

Given the code :

 A = [1 2 3; 3 2 1]
 B = A.^2

The output :

B =

     1     4     9
     9     4     1

But if I do this : B = A^2

The output is :

Error using  ^ 
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.

What does the operator . do exactly ?

This question is related to matlab syntax operators

The answer is


There is a whole page in the MATLAB documentation dedicated to this topic: Array vs. Matrix Operations. The gist of it is below:

MATLABĀ® has two different types of arithmetic operations: array operations and matrix operations. You can use these arithmetic operations to perform numeric computations, for example, adding two numbers, raising the elements of an array to a given power, or multiplying two matrices.

Matrix operations follow the rules of linear algebra. By contrast, array operations execute element by element operations and support multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are unnecessary.


Examples related to matlab

how to open .mat file without using MATLAB? SQL server stored procedure return a table Python equivalent to 'hold on' in Matlab Octave/Matlab: Adding new elements to a vector How can I make a "color map" plot in matlab? How to display (print) vector in Matlab? Correlation between two vectors? How to plot a 2D FFT in Matlab? How can I find the maximum value and its index in array in MATLAB? How to save a figure in MATLAB from the command line?

Examples related to syntax

What is the 'open' keyword in Swift? Check if returned value is not null and if so assign it, in one line, with one method call Inline for loop What does %>% function mean in R? R - " missing value where TRUE/FALSE needed " Printing variables in Python 3.4 How to replace multiple patterns at once with sed? What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript? How can I fix MySQL error #1064? What do >> and << mean in Python?

Examples related to operators

What is the difference between i = i + 1 and i += 1 in a 'for' loop? Using OR operator in a jquery if statement What is <=> (the 'Spaceship' Operator) in PHP 7? What does question mark and dot operator ?. mean in C# 6.0? Boolean operators ( &&, -a, ||, -o ) in Bash PowerShell and the -contains operator How do I print the percent sign(%) in c Using the && operator in an if statement What do these operators mean (** , ^ , %, //)? How to check if div element is empty