If the sizes of the two operands are incompatible, then you get an error.
A = [8 1 6; 3 5 7; 4 9 2]
A =
8
1
6
3
5
7
4
9
2
m = [2 4]
m =
2
4
A - m
Matrix dimensions must agree.
The following table provides a summary of arithmetic array operators in MATLAB. For functionspecific information, click the link to the function reference page in the last column.
Operator
Purpose
Description
Reference
Page
+
Addition
A+B adds A and B.
plus
+
Unary plus
+A returns A.
uplus
-
Subtraction
A-B subtracts B from A
minus
-
Unary minus
-A negates the elements of A.
uminus
.*
Element-wise
multiplication
A.*B is the element-by-element product of A and
B.
times
.^
Element-wise
power
A.^B is the matrix with elements A(i,j) to the
B(i,j) power.
power
./
Right array
division
A./B is the matrix with elements A(i,j)/
B(i,j).
rdivide
.\
Left array
division
A.\B is the matrix with elements B(i,j)/
A(i,j).
ldivide
.'
Array transpose A.' is the array transpose of A. For complex
matrices, this does not involve conjugation.
transpose
Matrix Operations
Matrix operations follow the rules of linear algebra and are not compatible with multidimensional
arrays. The required size and shape of the inputs in relation to one another depends on the operation.
For nonscalar inputs, the matrix operators generally calculate different answers than their array
operator counterparts.
For example, if you use the matrix right division operator, /, to divide two matrices, the matrices
must have the same number of columns. But if you use the matrix multiplication operator, *, to
multiply two matrices, then the matrices must have a common inner dimension. That is, the number
of columns in the first input must be equal to the number of rows in the second input. The matrix
multiplication operator calculates the product of two matrices with the formula,
2 Program Components
2-22
Précédent

- 72/1450

Suivant