The previous section described standard linear algebra matrix operations.
Alternatively, element-by-element matrix arithmetic is provided
by array operations. An array operator is formed by preceding
one of the symbols +, -, *, \, or / by a period (.).
Of course, the matrix and array operators for addition and subtraction
are equivalent, and + and - are used in either case.
The operator .* denotes array multiplication and is defined whenever
the two operands have the same dimensions. For example
>> A=[1 2 3; 4 5 6] ; B = [2 2 2; 3 3 5]; C=A.*B
results in
C =
2 4 6
12 15 30
Similarly, A.\B and A./B provide the left and right
element-by-element division.
Raising each element of a matrix to the same power is accomplished
by the .^ operator.
Most standard MATLAB functions operate on a matrix element-by-element. For
example
>> cos(C)
ans = -4.1615e-01 -6.5364e-01 9.6017e-01 8.4385e-01 -7.5969e-01 1.5425e-01If you create your own functions (See Section 11.) you should keep in mind that MATLAB assumes that a matrix (or a vector) can be passed to it.