check if an array is equispaced
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mireia Boneta Camí
le 12 Oct 2020
Modifié(e) : Stephen23
le 12 Oct 2020
I am given a vector of numbers and I have to check if this vector has its samples equispaced or not. How can I do it without using fors?
0 commentaires
Réponse acceptée
Ameer Hamza
le 12 Oct 2020
Modifié(e) : Ameer Hamza
le 12 Oct 2020
Something like this
x = [1 2 3];
dx = diff(x);
is_equidistant = all(dx==dx(1));
Result
>> is_equidistant
is_equidistant =
logical
1
If
x = [1 2 5];
dx = diff(x);
is_equidistant = all(dx==dx(1));
Result
>> is_equidistant
is_equidistant =
logical
0
If you want to check it with a tolerance value
x = [1 2 3.00000000000001];
dx = diff(x);
is_equidistant = all(ismembertol(dx, dx(1)));
Result
>> is_equidistant
is_equidistant =
logical
1
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!