Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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

collapse 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

collapse all

A — Input arrayscalar | vector | matrix | multidimensional array

Input array, specified as a scalar, vector, matrix, or multidimensional array. Inputs A and B must be the same size unless one is a scalar. A scalar value expands to be the same size as the other array.

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.

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

B — Input arrayscalar | vector | matrix | multidimensional array

Input array, specified as a scalar, vector, matrix, or multidimensional array. Inputs A and B must be the same size unless one is a scalar. A scalar value expands to be the same size as the other array.

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.

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

See Also

| | |

Introduced before R2006a

Was this topic helpful?