Documentation

plus, +

Syntax

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

expand all

Add Scalar to Array

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

A = [0 1; 1 0];
C = A + 2
C =

     2     3
     3     2

The scalar value is added to each entry of A.

Add Two Arrays

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

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

     6     9
     4     5

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

Input Arguments

expand all

A — Input arrayscalar | vector | matrix | multidimensional array

Input array, specified as a scalar, vector, matrix, or multidimensional array. A can be a numeric array, logical array, character array, datetime array, duration array, or calendar duration array. Inputs A and B must be the same size unless one is a scalar. You can add a scalar value to any other value.

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.

Complex Number Support: Yes

B — Input arrayscalar | vector | matrix | multidimensional array

Input array, specified as a scalar, vector, matrix, or multidimensional array. B can be a numeric array, logical array, character array, datetime array, duration array, or calendar duration array. Inputs A and B must be the same size unless one is a scalar. You can add a scalar value to any other value.

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.

Complex Number Support: Yes

See Also

| | |

Was this topic helpful?