# isuniform

Determine if vector is uniformly spaced

Since R2022b

## Syntax

``tf = isuniform(v)``
``[tf,step] = isuniform(v)``

## Description

example

````tf = isuniform(v)` returns the logical scalar `1` (`true`) when the elements of numeric vector `v` are uniformly spaced up to round-off tolerance and `0` (`false`) otherwise. The input `v` is uniformly spaced if its elements increase or decrease with a constant, finite step size.```

example

````[tf,step] = isuniform(v)` also returns the step size `step`. If `v` is uniformly spaced, then `step` is a scalar equal to the step size of `v`. If `v` is not uniformly spaced, then `step` is `NaN`.```

## Examples

collapse all

Create a vector and check if it is uniformly spaced.

```v = [3 6 9]; tf = isuniform(v)```
```tf = logical 1 ```

Change the first element of `v`. The vector is no longer uniformly spaced.

`v(1) = 12`
```v = 1×3 12 6 9 ```
`tf = isuniform(v)`
```tf = logical 0 ```

Sort the elements in `v` and check if the vector is uniformly spaced.

`v = sort(v)`
```v = 1×3 6 9 12 ```
`tf = isuniform(v)`
```tf = logical 1 ```

Create a vector with elements that increment by a specified value by using the colon. Then, check if the vector is uniformly spaced up to Round-Off Tolerance.

`v = [0:1/3:1]`
```v = 1×4 0 0.3333 0.6667 1.0000 ```
`tf = isuniform(v)`
```tf = logical 1 ```

Create a linearly spaced vector and check if it is uniformly spaced.

`v = linspace(10,-10,5)`
```v = 1×5 10 5 0 -5 -10 ```
`tf = isuniform(v)`
```tf = logical 1 ```

Create a vector of data. Check if it is uniformly spaced, and determine the step size between consecutive elements.

`v = [0 4 8 12]`
```v = 1×4 0 4 8 12 ```
`[tf,step] = isuniform(v)`
```tf = logical 1 ```
```step = 4 ```

Change the last element of v. The vector is no longer uniformly spaced, and the step size is returned as `NaN`.

`v(end) = 15`
```v = 1×4 0 4 8 15 ```
`[tf,step] = isuniform(v)`
```tf = logical 0 ```
```step = NaN ```

## Input Arguments

collapse all

Input vector, specified as a numeric vector.

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

## Output Arguments

collapse all

True or false result, returned as a logical `1` if the input is uniformly spaced and a logical `0` if it is not.

• If `v` is a scalar, then `tf` is `0`.

• If `v` is a two-element vector, then `tf` is `1`.

• If all elements of `v` are equal, then `tf` is `1`.

• If any element of `v` is `NaN`, then `tf` is `0`.

Data Types: `logical`

Step size between consecutive elements, returned as a numeric scalar.

If `v` has an integer type, then `step` is a `double`. Otherwise, `step` has the same type as `v`. For all types, if `v` is not uniformly spaced, then `step` is `NaN`.

Data Types: `single` | `double`

collapse all

### Round-Off Tolerance

`isuniform` verifies that the spacing between consecutive elements in numeric vector `v` does not deviate from the mean spacing by more than `4*eps(max(abs(v)))`, provided that the mean spacing is greater than that tolerance. For more information, see Floating-Point Numbers.

## Version History

Introduced in R2022b

expand all