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
Absolute Value of Scalar
Absolute Value of Vector
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
Magnitude of Complex Number
Input Arguments
X
— Input array
scalar | vector | matrix | multidimensional array | table | timetable
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
Absolute Value
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
.
Complex Magnitude
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
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
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™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
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).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using 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 R2006aR2023a: Perform calculations directly on tables and timetables
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.
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)