Logo Background

idivide

  • Written by matlabtutorialsmatlabtutorials No Comments Comments
    Last Updated: December 5, 2009

    idivide – Integer with rounding option
    Syntax

    1
    2
    3
    4
    5
    6
    
    C = idivide(A, B, opt)
    C = idivide(A, B)
    C = idivide(A, B, 'fix')
    C = idivide(A, B, 'round')
    C = idivide(A, B, 'floor')
    C = idivide(A, B, 'ceil')

    Description

    C = idivide(A, B, opt) is the same as A./B for integer classes except that fractional quotients are rounded to integers using the optional rounding mode specified by opt. The default rounding mode is ‘fix’. Inputs A and B must be real and must have the same dimensions unless one is a scalar. At least one of the arguments A and B must belong to an integer class, and the other must belong to the same integer class or be a scalar double. The result C belongs to the integer class.

    C = idivide(A, B) is the same as A./B except that fractional quotients are rounded toward zero to the nearest integers.

    C = idivide(A, B, ‘fix’) is the same as the syntax shown immediately above.

    C = idivide(A, B, ’round’) is the same as A./B for integer classes. Fractional quotients are rounded to the nearest integers.

    C = idivide(A, B, ‘floor’) is the same as A./B except that fractional quotients are rounded toward negative infinity to the nearest integers.

    C = idivide(A, B, ‘ceil’) is the same as A./B except that the fractional quotients are rounded toward infinity to the nearest integers.
    Examples

    1
    2
    3
    4
    5
    6
    7
    
    a = int32([-2 2]);
    b = int32(3);
     
    idivide(a,b)             % Returns [0 0]
    idivide(a,b,'floor')     % Returns [-1 0]
    idivide(a,b,'ceil')      % Returns [0 1]
    idivide(a,b,'round')     % Returns [-1 1]