# containsrange

## 语法

``tf = containsrange(TT,rangeOfTimes)``
``tf = containsrange(TT,oneTime)``
``[tf,whichRows] = containsrange(___)``

## 说明

`如果 `TT` 的行时间范围包含 `rangeOfTimes` 指定的时间范围，则 `tf = containsrange(TT,rangeOfTimes)` 返回 `1` (`true`)。否则，将返回 `0` (`false`)。`TT` 的行时间范围由其最小和最大行时间决定。`

``tf = containsrange(TT,oneTime)` 确定 `TT` 的行时间范围是否包含 `oneTime` 指定的时间。`

``[tf,whichRows] = containsrange(___)` 还返回逻辑索引，指示 `TT` 的哪些行在指定的时间范围内。`

## 示例

```Intensity = [100;98.7;95.2;101.4;99.1]; TT = timetable(Intensity,'TimeStep',seconds(0.1))```
```TT=5×1 timetable Time Intensity _______ _________ 0 sec 100 0.1 sec 98.7 0.2 sec 95.2 0.3 sec 101.4 0.4 sec 99.1 ```

`rangeOfTimes = timerange(seconds(0.1),seconds(0.35))`
```rangeOfTimes = timetable timerange subscript: Select timetable rows with times in the half-open interval: [0.1 sec, 0.35 sec) See Select Times in Timetable. ```

`tf = containsrange(TT,rangeOfTimes)`
```tf = logical 1 ```

`rangeOfTimes = timerange(seconds(0.1),seconds(0.9))`
```rangeOfTimes = timetable timerange subscript: Select timetable rows with times in the half-open interval: [0.1 sec, 0.9 sec) See Select Times in Timetable. ```
`tf = containsrange(TT,rangeOfTimes)`
```tf = logical 0 ```

```Intensity = [100;98.7;95.2;101.4;99.1]; TT1 = timetable(Intensity,'TimeStep',seconds(0.1))```
```TT1=5×1 timetable Time Intensity _______ _________ 0 sec 100 0.1 sec 98.7 0.2 sec 95.2 0.3 sec 101.4 0.4 sec 99.1 ```
```Readings = [74;83;99]; TT2 = timetable(Readings,'TimeStep',seconds(0.15),'StartTime',seconds(0.05))```
```TT2=3×1 timetable Time Readings ________ ________ 0.05 sec 74 0.2 sec 83 0.35 sec 99 ```

`tf = containsrange(TT1,TT2)`
```tf = logical 1 ```

`tf = containsrange(TT2,TT1)`
```tf = logical 0 ```

```Time = datetime({'2018-01-01';'2018-01-15';'2018-02-01';'2018-02-15'; '2018-03-01';'2018-03-15'}); Price = randi([85 110],6,1); TT = timetable(Time,Price)```
```TT=6×1 timetable Time Price ___________ _____ 01-Jan-2018 106 15-Jan-2018 108 01-Feb-2018 88 15-Feb-2018 108 01-Mar-2018 101 15-Mar-2018 87 ```

`oneTime = datetime('2018-02-01')`
```oneTime = datetime 01-Feb-2018 ```

`tf = containsrange(TT,oneTime)`
```tf = logical 1 ```

`oneTime` 不必与 `TT` 的某特定行时间相匹配。如果 `oneTime` 是介于 `TT` 的最小和最大行时间之间的任意时间，则 `containsrange` 返回 1。

`oneTime = datetime('2018-02-28 09:23:45')`
```oneTime = datetime 28-Feb-2018 09:23:45 ```
`tf = containsrange(TT,oneTime)`
```tf = logical 1 ```

```Intensity = [100;98.7;95.2;101.4;99.1]; TT = timetable(Intensity,'TimeStep',seconds(0.1))```
```TT=5×1 timetable Time Intensity _______ _________ 0 sec 100 0.1 sec 98.7 0.2 sec 95.2 0.3 sec 101.4 0.4 sec 99.1 ```

```rangeOfTimes = timerange(seconds(0.1),seconds(0.35)); [tf,whichRows] = containsrange(TT,rangeOfTimes)```
```tf = logical 1 ```
```whichRows = 5x1 logical array 0 1 1 1 0 ```

`TT2 = TT(whichRows,:)`
```TT2=3×1 timetable Time Intensity _______ _________ 0.1 sec 98.7 0.2 sec 95.2 0.3 sec 101.4 ```

## 输入参数

• 如果要使用时间范围对象，则使用 `timerange` 函数创建该对象，并将范围的开始和结束时间显式指定为 `timerange` 的输入。

• 如果您使用时间表，则不需要显式指定范围的开始和结束时间。`containsrange` 会自动从时间表的最小和最大行时间获取它们。

## 输出参数

true 或 false，如果 `TT` 的行时间范围包含 `rangeOfTimes` 指定的时间范围或 `oneTime` 指定的时间点，则返回逻辑值 `1`，否则返回逻辑值 `0`

```[tf,whichVars] = (TT,rangeOfTimes); TT2 = T(whichRows,:)```