Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Ajuda do Scilab >> Funções Elementares > 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 — valor absoluto, magnitude
  • csgn — returns the sign of a vector of real of complex values
  • signm — função do sinal da matriz

History

VersionDescription
6.0 Extension to sparse matrices
Report an issue
<< prod Matrix operations signm >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:52:28 CET 2020