Main Content

fixed.Interval

定义值的区间

自 R2019b 起

说明

fixed.Interval 对象定义真实值的区间。使用 Interval 对象指定 fixed.DataSpecification 对象中的值范围。

创建对象

描述

示例

interval = fixed.Interval 创建一个单位区间 [0,1]。

示例

interval = fixed.Interval(a) 创建一个退化区间,仅包含值 a

interval = fixed.Interval(a, b) 创建一个从 ab 的闭区间。

示例

interval = fixed.Interval(a, b, endnotes) 创建一个从 ab 的区间,其中 endnotes 参数指定该区间是开区间还是闭区间。

interval = fixed.Interval(a, b, Name, Value) 创建一个从 ab 的区间,将 IsLeftClosedIsRightClosed 属性指定为 Name, Value 对组参数。

示例

interval = fixed.Interval(numerictype) 创建一个区间或区间数组,其端点等于指定数值类型的最小和最大可表示值。

示例

interval = fixed.Interval({___}, ...,{___}) 返回一个 Interval 对象数组,其中每个元胞数组指定一个或多个对象的参数。

输入参数

全部展开

区间的左端点,指定为标量或向量。

区间的右端点,指定为标量或向量。

指示区间是闭区间、开区间还是半开区间的参数,指定为以下字符向量之一。

尾注描述
'[]'生成一个闭集,其中包含两个端点。
'[)'生成一个半开区间,其中包含第一个端点,但不包含第二个端点。
'(]'生成一个半开区间,其中不包含第一个端点,但包含第二个端点。
'()'生成一个开区间,其中两个端点都不包含在区间中。

示例: interval = fixed.Interval(1, 10, '()');

数值数据类型(其可表示值的范围定义 Interval 对象),指定为 Simulink.Numerictype 对象、embedded.numerictype 对象或表示数值数据类型的字符向量,例如 'single'

numerictype'double''single''half' 时,输出 Interval 对象是由 4 个 Interval 对象组成的数组,这些对象的区间为 [-Inf][Inf][NaN][-realmax, realmax]。有关数据类型的可表示值的详细信息,请参阅 realmax

示例: interval = fixed.Interval('fixdt(1,16,8)');

属性

全部展开

区间的左端点,指定为标量。

创建对象后,无法编辑此属性。

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | fi

区间的右端点,指定为标量。

创建对象后,无法编辑此属性。

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | fi

区间的左端是否闭合,指定为逻辑值。

创建对象后,无法编辑此属性。

数据类型: logical

区间的右端是否闭合,指定为逻辑值。

创建对象后,无法编辑此属性。

数据类型: logical

对象函数

containsDetermine if one fixed.Interval object contains another
intersectIntersection of fixed.Interval objects
isDegenerateDetermine whether the left and right ends of a fixed.Interval object are degenerate
isLeftBoundedDetermine whether a fixed.Interval object is left-bounded
isRightBoundedDetermine whether a fixed.Interval object is right-bounded
isnanDetermine whether a fixed.Interval object is NaN
overlaps确定两个 fixed.Interval 对象是否重叠
quantizeQuantize interval to range of numeric data type
setdiffSet difference of fixed.Interval objects
unionUnion of fixed.Interval objects
uniqueGet set of unique values in fixed.Interval object

示例

全部折叠

使用默认属性值创建一个 Interval 对象。当您不指定端点值时,Interval 对象使用端点 0 和 1。

interval = fixed.Interval()
interval = 
    [0,1]

  1x1 fixed.Interval with properties:

              LeftEnd: 0
             RightEnd: 1
         IsLeftClosed: true
        IsRightClosed: true

创建一个退化区间,只包含单个点。

interval = fixed.Interval(pi)
interval = 
    [3.1416]

  1x1 fixed.Interval with properties:

              LeftEnd: 3.1416
             RightEnd: 3.1416
         IsLeftClosed: true
        IsRightClosed: true

这等同于创建一个具有两个相等端点的区间。

interval = fixed.Interval(pi, pi)
interval = 
    [3.1416]

  1x1 fixed.Interval with properties:

              LeftEnd: 3.1416
             RightEnd: 3.1416
         IsLeftClosed: true
        IsRightClosed: true

指定区间端点符号以创建开区间。

interval = fixed.Interval(-1, 1,'()') %#ok<*NASGU> 
interval = 
    (-1,1)

  1x1 fixed.Interval with properties:

              LeftEnd: -1
             RightEnd: 1
         IsLeftClosed: false
        IsRightClosed: false

要创建包含第一个端点但不包含第二个端点的区间,请将端点符号指定为 '[)'

interval = fixed.Interval(-1, 1,'[)')
interval = 
    [-1,1)

  1x1 fixed.Interval with properties:

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

当您在 fixed.Interval 对象的构造函数中指定数值数据类型时,区间的范围将设置为该数据类型的范围。

创建一个范围为 int8 数据类型的区间。

interval_int8 = fixed.Interval('int8')
interval_int8 = 
    [-128,127]

  1x1 fixed.Interval with properties:

              LeftEnd: -128
             RightEnd: 127
         IsLeftClosed: true
        IsRightClosed: true

您还可以指定 Simulink.NumericType 来创建一个区间,其范围与 NumericType 对象的可表示范围相同。

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

要创建一个 fixed.Interval 对象数组,可以在 Interval 对象的构造函数中指定一系列元胞数组,每个元胞数组都包含一个 Interval 对象的参数。

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

版本历史记录

在 R2019b 中推出