size of zero must be paired with a dimension of size 1 or 0 in the other array, and that the output has
a dimension size of 0.
A: 1-by-0
B: 3-by-1
Result: 3-by-0
Inputs with Incompatible Sizes
Incompatible inputs have sizes that cannot be implicitly expanded to be the same size. For example:
• One of the dimension sizes are not equal, and neither is 1.
A: 3-by-2
B: 4-by-2
• Two nonscalar row vectors with lengths that are not the same.
A: 1-by-3
B: 1-by-4
Examples
Subtract Vector from Matrix
To simplify vector-matrix operations, use implicit expansion with dimensional functions such as sum,
mean, min, and others.
For example, calculate the mean value of each column in a matrix, then subtract the mean value from
each element.
A = magic(3)
A =
8
1
6
3
5
7
4
9
2
C = mean(A)
C =
5
5
5
A - C
ans =
3
-4
1
-2
0
2
-1
4
-3
Add Row and Column Vector
Row and column vectors have compatible sizes, and when you perform an operation on them the
result is a matrix.
Compatible Array Sizes for Basic Operations
2-27
Précédent

- 77/1450

Suivant