uminus

Unary minus: changes the sign of each element.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

B = uminus(A)

Negates every element of A. Same as -A.

Description

For unsigned integers the result saturates at 0: uminus(uint8(5)) is 0. For signed integers the most negative value saturates: -int8(-128) is 127. Complex values have both parts negated.

The function form is useful when a handle is needed, as in cellfun(@uminus, c).

Input arguments

A
Numeric, logical or char array.

Output arguments

B
Array of the same size holding -A. Logical and char inputs give double.

Example

uminus([1 -2 3])
uminus(uint8(5))
uminus(1 + 2i)
uminus(int8(-128))
Output
ans = 1×3

    -1     2    -3
ans = uint8
   0
ans = -1.0000 - 2.0000i
ans = int8
   127

See also

- uplus minus abs