Main Content

setdiff

Set difference of fixed.Interval objects

Since R2019b

Description

example

C = setdiff(A, B) returns a fixed.Interval object containing the values in fixed.Interval object A, but not in B.

Examples

collapse all

Create two fixed.Interval objects. Use the setdiff function to find the values that are in Interval object interval1 but not in interval2. In this example, interval1 contains all values between 0 and 1, but interval2 only contains values from 0 to 0.5, so the output Interval object has an interval from 0.5 to 1.

interval1 = fixed.Interval(0,1);
interval2 = fixed.Interval(0,0.5);
intervaldiff = setdiff(interval1, interval2)
intervaldiff = 
    (0.5000,1]

  1x1 fixed.Interval with properties:

              LeftEnd: 0.5000
             RightEnd: 1
         IsLeftClosed: false
        IsRightClosed: true

You can use the setdiff function to create an interval object based on another interval, while excluding zero.

Create an Interval object that contains zero.

myInterval = fixed.Interval(-1,1);

To create an interval based on the Interval object, myInterval, use the setdiff function. Include the constructor for a degenerate Interval object containing only zero as the second argument.

myInterval_nozero = setdiff(myInterval, {0});
myInterval_nozero = 

    [-1,0)    (0,1]

  1x2 fixed.Interval with properties:

              LeftEnd
             RightEnd
         IsLeftClosed
        IsRightClosed

The output Interval object, myInterval_nozero, contains two intervals, each with an open end point at zero. Therefore, the interval contains all values between -1 and 1, except 0.

Input Arguments

collapse all

Input fixed.Interval objects, specified as fixed.Interval objects, or arrays of fixed.Interval objects.

Output Arguments

collapse all

Set difference of input fixed.Interval objects, returned as a fixed.Interval object or an array of fixed.Interval objects.

The output Interval object contains all values in first input, A, but not in B.

Version History

Introduced in R2019b