Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

Why does COLON return a vector that does not seem to be correct?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-536MAS
Product:   MATLAB
Reported in Release:   No Release
Platform:   All Platforms
Operating System:   All OS
 

Subject:

Why does COLON return a vector that does not seem to be correct?

Problem Description:

When I create a vector using the COLON operator or the LINSPACE function, and then compare one of the elements to a variable with the same value, they are not equal. For example:
a = 0:0.1:1;
a(4)==0.3


ans =

0

Solution:

This behavior is related to floating-point arithmetic and the way numbers are represented in a computer. For more information on this subject, see the related Solution below.

 

Related Solutions:

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page