I have a vector of unique numbers and want to find the index for a

certain number. Tried to use the find function, but it seems very

unstable. The problem is best described by an example:

Say I create the following vector: [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8

0.9 1]. Then find(x==0.1) returns 2 and find(x==0.2) returns 3, but

find(x==0.3) returns en empty matrix!

Am I doing something wrong here, or have the find function just lost

its mind?

as Jerome pointed out already, this is a common issue in floating

point arithmetic.

it also depends on how you created the vector:

x1 = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]

x2 = 0:0.1:1

almost the same but see ...

x1==x2

Lesson: don't compare floating points using "==", but use a

tolerance:

abs(x1-x2)<eps

hth

Jos

2. Wierd behaviour of function 'strcspn'

3. Anyone experience wierd find behaviour?!?

4. Anyone experience wierd find behaviour?!? (solved)

5. WIERD WIERD WIERD tomcat/apache problem

6. Datagrid paging wierd behaviour

9. DataGridViewComboBoxCell wierd behavior

10. wierd behavior - no Exceptions thrown!

11. wierd behavior

12. Wierd Date listbox behaviour

14. Wierd Outlook Connection Behavior

15. Wierd cursor / index behavior

4 post • Page:**1** of **1**