Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: How to eliminate the zeros from a number
Replies: 4   Last Post: Aug 14, 2014 6:29 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Curious

Posts: 1,986
Registered: 12/6/04
Re: How to eliminate the zeros from a number
Posted: Aug 14, 2014 4:04 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.