1
2
3
1
2
3
3.*A
ans =
3
6
9
3
6
9
Implicit expansion also works if you subtract a 1-by-3 vector from a 3-by-3 matrix because the two
sizes are compatible. When you perform the subtraction, the vector is implicitly expanded to become
a 3-by-3 matrix.
A = [1 1 1; 2 2 2; 3 3 3]
A =
1
1
1
2
2
2
3
3
3
m = [2 4 6]
m =
2
4
6
A - m
ans =
-1
-3
-5
0
-2
-4
1
-1
-3
A row vector and a column vector have compatible sizes. If you add a 1-by-3 vector to a 2-by-1 vector,
then each vector implicitly expands into a 2-by-3 matrix before MATLAB executes the element-wise
addition.
x = [1 2 3]
x =
1
2
3
y = [10; 15]
y =
10
15
x + y
ans =
11
12
13
16
17
18
Array vs. Matrix Operations
2-21
2
3
1
2
3
3.*A
ans =
3
6
9
3
6
9
Implicit expansion also works if you subtract a 1-by-3 vector from a 3-by-3 matrix because the two
sizes are compatible. When you perform the subtraction, the vector is implicitly expanded to become
a 3-by-3 matrix.
A = [1 1 1; 2 2 2; 3 3 3]
A =
1
1
1
2
2
2
3
3
3
m = [2 4 6]
m =
2
4
6
A - m
ans =
-1
-3
-5
0
-2
-4
1
-1
-3
A row vector and a column vector have compatible sizes. If you add a 1-by-3 vector to a 2-by-1 vector,
then each vector implicitly expands into a 2-by-3 matrix before MATLAB executes the element-wise
addition.
x = [1 2 3]
x =
1
2
3
y = [10; 15]
y =
10
15
x + y
ans =
11
12
13
16
17
18
Array vs. Matrix Operations
2-21
