Main Content

sign

Perform sign function (signum function) on array

Description

c = sign(a) returns an array c the same size as a, where each element of c is:

  • 1 if the corresponding element of a is greater than 0.

  • 0 if the corresponding element of a is 0.

  • -1 if the corresponding element of a is less than 0.

The elements of c are of data type int8.

example

Examples

collapse all

Find the sign function of a fi object.

sign(fi(2))
ans =

  int8

   1

Find the sign function of a signed fi vector.

v = fi([-11 0 1.5],1);
sign(v)
ans =

  1×3 int8 row vector

   -1    0    1

Find the sign function of an unsigned fi vector.

u = fi([-11 0 1.5],0);
sign(u)
ans =

  1×3 int8 row vector

   0   0   1

Input Arguments

collapse all

Input array, specified as a fi scalar, vector, matrix, or multidimensional array.

sign does not support complex fi inputs.

Data Types: fi

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a

See Also

| |