Main Content


Subtract two arrays using fimath object



c = sub(F,a,b) subtracts arrays a and b using fimath object F. This is helpful in cases when you want to override the fimath objects of a and b, or if the fimath properties associated with a and b are different. The output has no local fimath.


collapse all

a = fi(pi);
b = fi(exp(1));
F = fimath('SumMode','SpecifyPrecision',...
c = sub(F,a,b)
c = 

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 16

c is the 32-bit difference of a and b, with fraction length 16.

Input Arguments

collapse all

fimath object to use for subtraction, specified as a fimath object.

Operands, specified as scalars, vectors, matrices, or multidimensional arrays.

a and b must have the same dimensions unless one is a scalar. If either a or b is scalar, then c has the dimensions of the nonscalar object.

If a or b is a fi object, then both a and b must be fi objects.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes


When you use the sub function, the fimath properties of A and B are not modified, and the output C has no local fimath.

C = sub(F,A,B)
C = F.sub(A,B)

is equivalent to

C = removefimath(setfimath(A,F) - setfimath(B,F))

Extended Capabilities

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

Version History

Introduced before R2006a

expand all