signum function
X = sign(A)
matrix of encoded integers, decimal numbers, or complex numbers.
A may be sparse.
matrix of the same size and data type as A.
If X are integers or real numbers,
X(i) = -1 where A(i)<0X(i) = 0 where A(i)==0X(i) = 1 where A(i)>0X(i)= %nan where A(i) is NaN.If X is complex encoded: sign(A==0) = 0.
Elsewhere, sign(A) = A./abs(A).
With decimal numbers:
--> m = 1.25 -2.5 -Inf 2.75 0. 1. 0.75 Inf Nan 0. -1.5 -2.5 --> sign(m) ans = 1. -1. -1. 1. 0. 1. 1. 1. Nan 0. -1. -1.
With complex numbers:
--> c = -1. -i -3. + 4.i 1. i 3. + 4.i 3. 0. 3. - 4.i -4. 4.i -4. - 3.i --> sign(c) ans = -1. -i -0.6 + 0.8i 1. i 0.6 + 0.8i 1. 0. 0.6 - 0.8i -1. i -0.8 - 0.6i
With a sparse matrix:
sign(sprand(8,3,0.3,"normal")) | ![]() | ![]() |
| Version | Description |
| 6.0 | Extension to sparse matrices |