Curious
Posts:
1,986
Registered:
12/6/04


Re: How to eliminate the zeros from a number
Posted:
Aug 14, 2014 4:04 PM


"Andrea Clerico" <andrea.clerico@hotmail.it> wrote in message <lsj2aq$n3o$1@newscl01ah.mathworks.com>... > Hello everyone, > > I am experiencing a problem with the same number but written in two different ways. > > In a function that I am writing I have to use the function 'floor' for a vector. The result is that the numbers are written in this way: > > A = [0.5000000000000,0.6000000000000000,0.700000000000000,0.80000000000000,0.9000000000000000,1.0000000000000000]; > > > Once done that, I have to use the function 'intersect' with the vector > B = [0,1,2,3,4,5,6,7,8,9,10]; > > to understand how many and which elements they have in common. > > The problem is that Matlab thinks that the numbers > 1.000000000000000000000 and 1 are different. > > How can I solve this problem?? > Thank you very much for your help. > > Andrea
You may want to take a look at this link from the MATLAB FAQ:
<<http://matlab.wikia.com/wiki/FAQ#Why_is_0.3__0.2__0.1_.28or_similar.29_not_equal_to_zero.3F>>
Do you really have to use intersect? Although intersect works with numeric arrays, the examples shown in
doc intersect
are only for integers.
The above link shows how to compare floating point numbers that are "close enough" if that helps.

