abs - Absolute value and complex magnitude - MATLAB (original) (raw)

Main Content

Absolute value and complex magnitude

Syntax

Description

Examples

collapse all

Create a numeric vector of real values.

x = [1.3 -3.56 8.23 -5 -0.01]'

x = 5×1

1.3000

-3.5600 8.2300 -5.0000 -0.0100

Find the absolute value of the elements of the vector.

y = 5×1

1.3000
3.5600
8.2300
5.0000
0.0100

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable. If X is complex, then it must be a single ordouble array. The size and data type of the output array is the same as the input array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | duration | table | timetable

More About

collapse all

The absolute value (or modulus) of a real number is the corresponding nonnegative value that disregards the sign.

For a real value, a, the absolute value is:

abs(-0) returns 0.

The complex magnitude (or modulus) is the length of a vector from the origin to a complex value plotted in the complex plane.

For a complex value, |a+bi| is defined as a2+b2.

Extended Capabilities

expand all

Theabs function fully supports tall arrays. For more information, see Tall Arrays.

The abs function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced before R2006a

expand all

The abs function can calculate on all variables within a table or timetable without indexing to access those variables. All variables must have data types that support the calculation. For more information, see Direct Calculations on Tables and Timetables.