abs
Absolute value and complex magnitude
Syntax
Description
Y = abs(
returns the absolute value of each element in input X
)X
.
If X
is complex, abs(X)
returns the complex magnitude.
Examples
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 = abs(x)
y = 5×1
1.3000
3.5600
8.2300
5.0000
0.0100
Input Arguments
Input array, specified as a scalar, vector, matrix, multidimensional array, table, or
timetable. If X
is complex, then it must be a single
or
double
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
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:
a
, ifa
is greater than or equal to zero-a
, ifa
is less than zero
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, is defined as .
Extended Capabilities
The
abs
function fully supports tall arrays. For more information,
see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
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).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006aThe 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.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)