isuniform - Determine if vector is uniformly spaced - MATLAB (original) (raw)

Determine if vector is uniformly spaced

Since R2022b

Syntax

Description

[tf](#mw%5F8b997eb9-13f2-45ba-bc77-06d92f3730f5) = isuniform([v](#mw%5F3aac721e-29b4-45b4-a8af-7d54be4c158e)) 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 inputv is uniformly spaced if its elements increase or decrease with a constant, finite step size.

example

[[tf](#mw%5F8b997eb9-13f2-45ba-bc77-06d92f3730f5),[step](#mw%5Fbde70735-82eb-485e-bd58-d8cb37e9c17d)] = isuniform([v](#mw%5F3aac721e-29b4-45b4-a8af-7d54be4c158e)) also returns the step size step. If v is uniformly spaced, then step is a scalar equal to the step size ofv. If v is not uniformly spaced, thenstep is NaN.

example

Examples

collapse all

Create a vector and check if it is uniformly spaced.

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

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

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

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 = 1×4

     0    0.3333    0.6667    1.0000

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

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

Change the last element of v. The vector is no longer uniformly spaced, and the step size is returned as 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.

Data Types: logical

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

If v has an integer type, then step is adouble. Otherwise, step has the same type asv. For all types, if v is not uniformly spaced, then step is NaN.

Data Types: single | double

More About

collapse all

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.

Extended Capabilities

expand all

Theisuniform function fully supports tall arrays. For more information, see Tall Arrays.

The isuniform function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2022b

expand all

Generate C or C++ code for the isuniform function.