# 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

collapse 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

collapse 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.

If one input is a datetime array, then the other input also can be a date string or a cell array containing date strings.

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.

If one input is a datetime array, then the other input also can be a date string or a cell array containing date strings.

Complex Number Support: Yes