# fixed.Interval

Define interval of values

## Description

A `fixed.Interval` object defines an interval of real-world values. Use the `Interval` object to specify a range of values in a `fixed.DataSpecification` object.

## Creation

### Syntax

``interval = fixed.Interval``
``interval = fixed.Interval(a)``
``interval = fixed.Interval(a, b)``
``interval = fixed.Interval(a, b, endnotes)``
``interval = fixed.Interval(a, b, Name, Value)``
``interval = fixed.Interval(numerictype)``
``interval = fixed.Interval({___}, ...,{___})``

### Description

example

````interval = fixed.Interval` creates a unit interval, [0,1].```

example

````interval = fixed.Interval(a)` creates a degenerate interval, containing only the value `a`.```
````interval = fixed.Interval(a, b)` creates a closed interval from `a` to `b`.```

example

````interval = fixed.Interval(a, b, endnotes)` creates an interval from `a` to `b`, with the `endnotes` argument specifying whether the interval is open or closed.```
````interval = fixed.Interval(a, b, Name, Value)` creates an interval from `a` to `b` with the `IsLeftClosed` and `IsRightClosed` properties specified as `Name, Value` pair arguments.```

example

````interval = fixed.Interval(numerictype)` creates an interval or array of intervals with end points equal to the minimum and maximum representable values of the specified numeric type.```

example

````interval = fixed.Interval({___}, ...,{___})` returns an array of `Interval` objects, where each cell array specifies the arguments for one or more of the objects.```

### Input Arguments

expand all

Left endpoint of interval, specified as a scalar or vector.

Right endpoint of interval, specified as a scalar or vector.

Argument indicating whether the interval is closed, open, or half-open, specified as one of the following character vectors.

EndnotesDescription
`'[]'`Generates a closed set, which includes both of its endpoints.
`'[)'`Generates a half-open interval, in which the first endpoint is included, but the second is not included in the set.
`'(]'`Generates a half-open interval, in which the first endpoint is not included, but the second is included in the set.
`'()'`Generates an open set, in which neither endpoint is included in the set.

Example: `interval = fixed.Interval(1, 10, '()');`

Numeric data type whose range of representable values defines the `Interval` object, specified as a `Simulink.Numerictype` object, an `embedded.numerictype` object, or a character vector representing a numeric data type, for example, `'single'`.

When `numerictype` is `'double'`, `'single'`, or `'half'`, the output `Interval` object is an array of 4 `Interval` objects with intervals `[-Inf]`, `[Inf]`, `[NaN]`, and `[-realmax, realmax]`. For more information on representable values of a data type, see `realmax`.

Example: ```interval = fixed.Interval('fixdt(1,16,8)');```

## Properties

expand all

Left endpoint of interval, specified as a scalar.

This property cannot be edited after object creation.

Data Types: `half` | `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `logical` | `fi`

Right endpoint of interval, specified as a scalar.

This property cannot be edited after object creation.

Data Types: `half` | `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `logical` | `fi`

Whether the left end of the interval is closed, specified as a logical value.

This property cannot be edited after object creation.

Data Types: `logical`

Whether the right end of the interval is closed, specified as a logical value.

This property cannot be edited after object creation.

Data Types: `logical`

## Object Functions

 `contains` Determine if one `fixed.Interval` object contains another `intersect` Intersection of `fixed.Interval` objects `isDegenerate` Determine whether the left and right ends of a `fixed.Interval` object are degenerate `isLeftBounded` Determine whether a `fixed.Interval` object is left-bounded `isRightBounded` Determine whether the a `fixed.Interval` object is right-bounded `isnan` Determine whether a `fixed.Interval` object is NaN `overlaps` Determine if two `fixed.Interval` objects overlap `quantize` Quantize interval to range of numeric data type `setdiff` Set difference of `fixed.Interval` objects `union` Union of `fixed.Interval` objects `unique` Get set of unique values in `fixed.Interval` object

## Examples

collapse all

Create an `Interval` object with default property values. When you do not specify endpoint values, the `Interval` object uses endpoints 0 and 1.

`interval = fixed.Interval()`
```interval = [0,1] 1x1 fixed.Interval with properties: LeftEnd: 0 RightEnd: 1 IsLeftClosed: true IsRightClosed: true ```

Create a degenerate interval, containing only a single point.

`interval = fixed.Interval(pi)`
```interval = [3.1416] 1x1 fixed.Interval with properties: LeftEnd: 3.1416 RightEnd: 3.1416 IsLeftClosed: true IsRightClosed: true ```

This is equivalent to creating an interval with two equivalent endpoints.

`interval = fixed.Interval(pi, pi)`
```interval = [3.1416] 1x1 fixed.Interval with properties: LeftEnd: 3.1416 RightEnd: 3.1416 IsLeftClosed: true IsRightClosed: true ```

Specify end notes for an interval to create an open interval.

`interval = fixed.Interval(-1, 1,'()') %#ok<*NASGU> `
```interval = (-1,1) 1x1 fixed.Interval with properties: LeftEnd: -1 RightEnd: 1 IsLeftClosed: false IsRightClosed: false ```

To create an interval that includes the first endpoint, but not the second, specify the end notes as `'[)'`

`interval = fixed.Interval(-1, 1,'[)')`
```interval = [-1,1) 1x1 fixed.Interval with properties: LeftEnd: -1 RightEnd: 1 IsLeftClosed: true IsRightClosed: false ```

When you specify a numeric data type in the constructor of the `fixed.Interval` object, the range of the interval is set to the range of the data type.

Create an interval with the range of an `int8` data type.

`interval_int8 = fixed.Interval('int8')`
```interval_int8 = [-128,127] 1x1 fixed.Interval with properties: LeftEnd: -128 RightEnd: 127 IsLeftClosed: true IsRightClosed: true ```

You can also specify a `Simulink.NumericType` to create an interval with the same range as the range representable by the `NumericType` object.

```myNumericType = Simulink.NumericType; myNumericType.DataTypeMode = "Fixed-point: binary point scaling"; myNumericType.Signedness = 'Unsigned'; myNumericType.WordLength = 16; myNumericType.FractionLength = 14```
```myNumericType = NumericType with properties: DataTypeMode: 'Fixed-point: binary point scaling' Signedness: 'Unsigned' WordLength: 16 FractionLength: 14 IsAlias: 0 DataScope: 'Auto' HeaderFile: '' Description: '' ```
`interval_16_14 = fixed.Interval(myNumericType)`
```interval_16_14 = [0,3.9999] 1x1 fixed.Interval with properties: LeftEnd: 0 RightEnd: 3.9999 IsLeftClosed: true IsRightClosed: true ```

To create an array of `fixed.Interval` objects, in the constructor of the `Interval` object, you can specify a series of cell arrays, each of which contain the arguments of an `Interval` object.

```intervalarray = fixed.Interval({-1,1},{5,10,'[)'},... {1000,1500,'IsLeftClosed',1,'IsRightClosed',0},... {'int8'})```
```intervalarray = [-1,1] [5,10) [1000,1500) [-128,127] 1x4 fixed.Interval with properties: LeftEnd RightEnd IsLeftClosed IsRightClosed ```

## Version History

Introduced in R2019b