# How can I find the position of a real number in a vector?

2 vues (au cours des 30 derniers jours)
Cantor Set le 5 Mar 2020
Modifié(e) : James Tursa le 5 Mar 2020
I have a vector v:
v=[-0.9990;0.8988;2;3];
I want to find the position of -0.9990.
I used find(x==-0.9990) it does not work.
Any solutions?
Thanks
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

James Tursa le 5 Mar 2020
Modifié(e) : James Tursa le 5 Mar 2020
Welcome to the world of floating point arithmetic. The number you are searching for cannot be represented exactly in IEEE double precision, so calculations involving it are subject to roundoff errors.
You will need to do the search with some tolerance. E.g.,
find( abs(x - (-0.9990)) < 1e-10 )
P.S. Your example actually does work if you use "v" instead of "x". I am assuming your actual v is built differently. Or maybe the typo is the entire problem.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Plus de réponses (1)

Cameron B le 5 Mar 2020
find(v==-0.999)
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Matrices and 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!

Translated by