Documentation

### This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the page.

# plus, +

## Syntax

``C = A + B``
``C = plus(A,B)``

## Description

example

````C = A + B` adds arrays `A` and `B` and returns the result in `C`.```
````C = plus(A,B)` is an alternate way to execute `A + B`, but is rarely used. It enables operator overloading for classes.```

## Examples

collapse all

Create an array, `A`, and add a scalar value to it.

```A = [0 1; 1 0]; C = A + 2```
```C = 2×2 2 3 3 2 ```

The scalar value is added to each entry of `A`.

Create two arrays, `A` and `B`, and add them together.

```A = [1 0; 2 4]; B = [5 9; 2 1]; C = A + B```
```C = 2×2 6 9 4 5 ```

The elements of `A` are added to the corresponding elements of `B`.

Create an array, `A`, and add a column vector to it. The vector is treated as though it is a matrix of the same size as `A`, so that each element in the vector is added to a row in `A`.

`A = [1 2 3; 4 5 6]`
```A = 2×3 1 2 3 4 5 6 ```
`b = [10; 100]`
```b = 2×1 10 100 ```
`A + b`
```ans = 2×3 11 12 13 104 105 106 ```

Create two 1-by-3 string arrays, then concatenate similarly located strings in the arrays.

`s1 = string({'Red' 'Blue' 'Green'})`
```s1 = 1x3 string array "Red" "Blue" "Green" ```
`s2 = string({'Truck' 'Sky' 'Tree'})`
```s2 = 1x3 string array "Truck" "Sky" "Tree" ```
`s = s1 + s2`
```s = 1x3 string array "RedTruck" "BlueSky" "GreenTree" ```

## Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array. Numeric or string inputs `A` and `B` must either be the same size or have sizes that are compatible (for example, `A` is an `M`-by-`N` matrix and `B` is a scalar or `1`-by-`N` row vector). For more information, see Compatible Array Sizes for Basic Operations.

Datetime, duration, and calendar duration arrays must be the same size unless one is a scalar.

• If one input is a datetime array, duration array, or calendar duration array, then numeric values in the other input are treated as a number of 24-hour days.

• If one input is a string array, then the other input can be a numeric, logical, character, string, or cell array.

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

Input array, specified as a scalar, vector, matrix, or multidimensional array. Numeric or string inputs `A` and `B` must either be the same size or have sizes that are compatible (for example, `A` is an `M`-by-`N` matrix and `B` is a scalar or `1`-by-`N` row vector). For more information, see Compatible Array Sizes for Basic Operations.

Datetime, duration, and calendar duration arrays must be the same size unless one is a scalar.

• If one input is a datetime array, duration array, or calendar duration array, then numeric values in the other input are treated as a number of 24-hour days.

• If one input is a string array, then the other input can be a numeric, logical, character, string, or cell array.

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