+

Addition operator: adds numbers, arrays and other values element by element.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

C = A + B

Adds A and B. Same as plus(A, B).

Description

Sizes are compatible when, for each dimension, they are equal or one of them is 1. A size-1 dimension is expanded to match the other, so a column plus a row gives a matrix. Integer arithmetic saturates at the limits of the type, and adding two different integer types is an error.

Input arguments

A, B
Numeric, logical or char arrays, or objects that define plus. The sizes must be compatible.

Output arguments

C
The sum, with the size produced by implicit expansion.

Example

[1 2 3] + 10
[1; 2] + [10 20 30]
int8(100) + int8(100)
Output
ans = 1×3

    11    12    13
ans = 2×3

    11    21    31
    12    22    32
ans = int8
   127

See also

plus - .* sum