Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: Français - Português - 日本語 - Русский
Scilab Help >> Elementary Functions > Matrix operations > sign

sign

signum function

Syntax

X = sign(A)

Arguments

А

matrix of encoded integers, decimal numbers, or complex numbers. A may be sparse.

X

matrix of the same size and data type as A.

Description

If X are integers or real numbers,

  • X(i) = -1 where A(i)<0
  • X(i) = 0 where A(i)==0
  • X(i) = 1 where A(i)>0
  • X(i)= %nan where A(i) is NaN.

If X is complex encoded: sign(A==0) = 0. Elsewhere, sign(A) = A./abs(A).

Examples

With decimal numbers:

m  = [ 1.25  -2.5  -%inf   2.75
       0.     1.    0.75   %inf
       %nan   0.   -1.5   -2.5 ]; m
sign(m)
--> 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:

i = %i;
c = [-1, -i, -3+4*i
      1,  i,  3+4*i
      3,  0,  3-4*i
     -4, 4*i,-4-3*i ];
c
sign(c)
--> 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"))

See also

  • abs — absolute value, magnitude
  • csgn — returns the sign of a vector of real of complex values
  • signm — matrix signum function

History

VersionDescription
6.0 Extension to sparse matrices
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 14:57:13 CET 2019