Returns the absolute value of the input array for all elements. The general syntax for its use is
y = abs(x)
where x is an n-dimensional array of numerical type. The output
is the same numerical type as the input, unless the input is complex
or dcomplex. For complex inputs, the absolute value is a floating
point array, so that the return type is float. For dcomplex
inputs, the absolute value is a double precision floating point array, so that
the return type is double.
The following demonstrates the abs applied to a complex scalar.
--> abs(3+4*i)
ans =
<float> - size: [1 1]
5.0000000
The abs function applied to integer and real values:
--> abs([-2,3,-4,5])
ans =
<int32> - size: [1 4]
Columns 1 to 4
2 3 4 5
For a double-precision complex array,
--> abs([2.0+3.0*i,i])
ans =
<double> - size: [1 2]
Columns 1 to 2
3.605551275463989 1.000000000000000