# withinrange

## 语法

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

## 说明

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

`如果 `TT` 的行时间都相同并且都等于 `oneTime` 指定的时间，则 `tf = withinrange(TT,oneTime)` 返回 `1`。`

``[tf,whichRows] = withinrange(___)` 还返回逻辑索引，指示 `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(-1),seconds(1))`
```rangeOfTimes = timetable timerange subscript: Select timetable rows with times in the half-open interval: [-1 sec, 1 sec) See Select Times in Timetable. ```

`tf = withinrange(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 = withinrange(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;75;87;93;92]; TT2 = timetable(Readings,'TimeStep',seconds(0.1),'StartTime',seconds(-0.1))```
```TT2=7×1 timetable Time Readings ________ ________ -0.1 sec 74 0 sec 83 0.1 sec 99 0.2 sec 75 0.3 sec 87 0.4 sec 93 0.5 sec 92 ```

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

`tf = withinrange(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 = withinrange(TT,oneTime)`
```tf = logical 0 ```

`TT.Time(1:end) = oneTime`
```TT=6×1 timetable Time Price ___________ _____ 01-Feb-2018 106 01-Feb-2018 108 01-Feb-2018 88 01-Feb-2018 108 01-Feb-2018 101 01-Feb-2018 87 ```
`tf = withinrange(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] = withinrange(TT,rangeOfTimes)```
```tf = logical 0 ```
```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` 的输入。

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

## 输出参数

True 或 false，如果 `TT` 的行时间范围完全在 `rangeOfTimes` 指定的时间范围内，则返回逻辑值 `1`，否则返回逻辑值 `0`

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