Skip to content

dot

Dot product

C = dot(A, B)

  • C contains dot products of vectors taken from A and B along the first non-singleton dimension.
  • A and B should have the same sizes.

C = dot(A, B, dim)

  • C contains dot products of vectors taken from A and B along the dim-th dimension.
  • A and B should have the same sizes.
  • dim should be positive integer not greater than the number of dimensions of A or B.

Example 1: Dot products of vectors along different dimensions.

a=randi(3,3,4)
b=randi(3,3,4)

% Dot products of vectors along the first
% non-singleton dimension.
dot(a,b)

% Dot products of vectors along the
% second dimension.
dot(a,b,2)
a =
2.000   3.000   2.000   3.000
2.000   3.000   1.000   1.000
2.000   2.000   2.000   1.000

b =
3.000   3.000   2.000   2.000
1.000   2.000   3.000   3.000
3.000   2.000   1.000   1.000

ans =
14.00   19.00   9.000   10.00

ans = 
25.00
14.00
13.00