.*

Element-wise multiplication operator.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

C = A .* B

Multiplies corresponding elements of A and B. Same as times(A, B).

Description

Each element of A is multiplied by the element at the same position in B. A size-1 dimension is stretched to match the other operand, so (1:3)' .* (1:3) builds a multiplication table. This is different from *, which performs matrix multiplication.

Integer types saturate at their limits, and combining two different integer types is an error.

Input arguments

A, B
Numeric or logical arrays with compatible sizes.

Output arguments

C
Array of products, with the size given by implicit expansion.

Example

[1 2 3] .* [4 5 6]
(1:3)' .* (1:4)
int8(100) .* int8(2)
Output
ans = 1×3

     4    10    18
ans = 3×4

     1     2     3     4
     2     4     6     8
     3     6     9    12
ans = int8
   127

See also

times * ./ .^ prod