Accelerating the pace of engineering and science

# Documentation Center

• Trials
• Product Updates

# minus, -

## Description

example

C = A - B subtracts array B from array A and returns the result in C.

C = minus(A,B) is an alternate way to execute A - B, but is rarely used. It enables operator overloading for classes.

## Examples

expand all

### Subtract Scalar from Array

Create an array, A, and subtract a scalar value from it.

```A = [2 1; 3 5];
C = A - 2
```
```C =

0    -1
1     3```

The scalar is subtracted from each entry of A.

### Subtract Two Arrays

Create two arrays, A and B, and subtract the second, B, from the first, A.

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

-4    -9
0     3```

The elements of B are subtracted from the corresponding elements of A.

Use the syntax -C to negate the elements of C.

`-C`
```ans =

4     9
0    -3```

## Input Arguments

expand 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. You can add a scalar value to any other value.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char
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. You can add a scalar value to any other value.

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

## See Also

Was this topic helpful?