Documentation

times, .*

Element-wise multiplication

Syntax

C = A.*B
C = times(A,B)

Description

example

C =A.*Bmultiplies arraysAandBelement by element and returns the result inC.

C = times(A,B)is an alternate way to executeA.*B, but is rarely used. It enables operator overloading for classes.

Examples

collapse all

创建两个向量,AandB, and multiply them element by element.

A = [1 0 3]; B = [2 3 7]; C = A.*B
C =2 0 21

Create two 3-by-3 arrays,AandB, and multiply them element by element.

A = [1 0 3; 5 3 8; 2 4 6]; B = [2 3 7; 9 1 5; 8 8 3]; C = A.*B
C =2 0 21 45 3 40 16 32 18

Create a row vectoraand a column vectorb, then multiply them. The 1-by-3 row vector and 6-by-1 column vector combine to produce a 6-by-3 matrix with all combinations of elements multiplied.

a = [1 2 3]
a =1 2 3
b =(1:6)'
b =1 2 3 4 5 6
a.*b
ans =1 2 3 2 4 6 3 6 9 4 8 12 5 10 15 6 12 18

Input Arguments

collapse all

Left array, specified as a scalar, vector, matrix, or multidimensional array. Numeric inputsAandBmust either be the same size or have sizes that are compatible (for example,Ais anM-by-Nmatrix andBis a scalar or1-by-Nrow vector). For more information, seeCompatible Array Sizes for Basic Operations.

IfAandBare datetime, duration, or calendar duration arrays, then they must be the same size unless one is a scalar.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical|char|categorical|duration|calendarDuration
Complex Number Support:Yes

Right array, specified as a scalar, vector, matrix, or multidimensional array. Numeric inputsAandBmust either be the same size or have sizes that are compatible (for example,Ais anM-by-Nmatrix andBis a scalar or1-by-Nrow vector). For more information, seeCompatible Array Sizes for Basic Operations.

IfAandBare datetime, duration, or calendar duration arrays, then they must be the same size unless one is a scalar.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical|char|categorical|duration|calendarDuration
Complex Number Support:Yes

Extended Capabilities

Introduced before R2006a

Was this topic helpful?