isuniform
Tests whether the elements of a vector are evenly spaced.
Category: Language Fundamentals > Matrices and Arrays
Syntax
tf = isuniform(v)
True when consecutive differences are all equal, within rounding.
[tf, delta] = isuniform(v)
Also returns the common spacing.
Description
Floating point values such as 0:0.1:0.3 differ by amounts that are not exactly equal, so the test allows a small tolerance relative to the spacing. Uniform sample points are a precondition for some fast algorithms, for instance FFT-based methods and fast interpolation.
Input arguments
v- Numeric vector, with at least two elements to be uniform.
Output arguments
tf- Logical scalar.
delta- The spacing between neighbours when
tfis true.
Example
isuniform([0 0.1 0.2 0.3])
isuniform([1 2 4])
[tf, d] = isuniform([2 4 6])
Output
ans = logical
1
ans = logical
0
tf = logical
1
d = 2