Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 154945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:04:07+00:00 2026-05-11T10:04:07+00:00

I am writing a program where I need to delete duplicate points stored in

  • 0

I am writing a program where I need to delete duplicate points stored in a matrix. The problem is that when it comes to check whether those points are in the matrix, MATLAB can’t recognize them in the matrix although they exist.

In the following code, intersections function gets the intersection points:

[points(:,1), points(:,2)] = intersections(...     obj.modifiedVGVertices(1,:), obj.modifiedVGVertices(2,:), ...     [vertex1(1) vertex2(1)], [vertex1(2) vertex2(2)]); 

The result:

>> points points =    12.0000   15.0000    33.0000   24.0000    33.0000   24.0000  >> vertex1 vertex1 =     12     15  >> vertex2     vertex2 =     33     24 

Two points (vertex1 and vertex2) should be eliminated from the result. It should be done by the below commands:

points = points((points(:,1) ~= vertex1(1)) | (points(:,2) ~= vertex1(2)), :); points = points((points(:,1) ~= vertex2(1)) | (points(:,2) ~= vertex2(2)), :); 

After doing that, we have this unexpected outcome:

>> points points =    33.0000   24.0000 

The outcome should be an empty matrix. As you can see, the first (or second?) pair of [33.0000 24.0000] has been eliminated, but not the second one.

Then I checked these two expressions:

>> points(1) ~= vertex2(1) ans =      0 >> points(2) ~= vertex2(2) ans =      1   % <-- It means 24.0000 is not equal to 24.0000? 

What is the problem?


More surprisingly, I made a new script that has only these commands:

points = [12.0000   15.0000           33.0000   24.0000           33.0000   24.0000];  vertex1 = [12 ;  15]; vertex2 = [33 ;  24];  points = points((points(:,1) ~= vertex1(1)) | (points(:,2) ~= vertex1(2)), :); points = points((points(:,1) ~= vertex2(1)) | (points(:,2) ~= vertex2(2)), :); 

The result as expected:

>> points points =      Empty matrix: 0-by-2 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:04:08+00:00Added an answer on May 11, 2026 at 10:04 am

    The problem you’re having relates to how floating-point numbers are represented on a computer. A more detailed discussion of floating-point representations appears towards the end of my answer (The ‘Floating-point representation’ section). The TL;DR version: because computers have finite amounts of memory, numbers can only be represented with finite precision. Thus, the accuracy of floating-point numbers is limited to a certain number of decimal places (about 16 significant digits for double-precision values, the default used in MATLAB).

    Actual vs. displayed precision

    Now to address the specific example in the question… while 24.0000 and 24.0000 are displayed in the same manner, it turns out that they actually differ by very small decimal amounts in this case. You don’t see it because MATLAB only displays 4 significant digits by default, keeping the overall display neat and tidy. If you want to see the full precision, you should either issue the format long command or view a hexadecimal representation of the number:

    >> pi ans =     3.1416 >> format long >> pi ans =    3.141592653589793 >> num2hex(pi) ans = 400921fb54442d18 

    Initialized values vs. computed values

    Since there are only a finite number of values that can be represented for a floating-point number, it’s possible for a computation to result in a value that falls between two of these representations. In such a case, the result has to be rounded off to one of them. This introduces a small machine-precision error. This also means that initializing a value directly or by some computation can give slightly different results. For example, the value 0.1 doesn’t have an exact floating-point representation (i.e. it gets slightly rounded off), and so you end up with counter-intuitive results like this due to the way round-off errors accumulate:

    >> a=sum([0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1]);  % Sum 10 0.1s >> b=1;                                               % Initialize to 1 >> a == b ans =   logical    0                % They are unequal! >> num2hex(a)       % Let's check their hex representation to confirm ans = 3fefffffffffffff >> num2hex(b) ans = 3ff0000000000000 

    How to correctly handle floating-point comparisons

    Since floating-point values can differ by very small amounts, any comparisons should be done by checking that the values are within some range (i.e. tolerance) of one another, as opposed to exactly equal to each other. For example:

    a = 24; b = 24.000001; tolerance = 0.001; if abs(a-b) < tolerance, disp('Equal!'); end 

    will display ‘Equal!’.

    You could then change your code to something like:

    points = points((abs(points(:,1)-vertex1(1)) > tolerance) | ...                 (abs(points(:,2)-vertex1(2)) > tolerance),:) 

    Floating-point representation

    A good overview of floating-point numbers (and specifically the IEEE 754 standard for floating-point arithmetic) is What Every Computer Scientist Should Know About Floating-Point Arithmetic by David Goldberg.

    A binary floating-point number is actually represented by three integers: a sign bit s, a significand (or coefficient/fraction) b, and an exponent e. For double-precision floating-point format, each number is represented by 64 bits laid out in memory as follows:

    enter image description here

    The real value can then be found with the following formula:

    enter image description here

    This format allows for number representations in the range 10^-308 to 10^308. For MATLAB you can get these limits from realmin and realmax:

    >> realmin ans =     2.225073858507201e-308 >> realmax ans =     1.797693134862316e+308 

    Since there are a finite number of bits used to represent a floating-point number, there are only so many finite numbers that can be represented within the above given range. Computations will often result in a value that doesn’t exactly match one of these finite representations, so the values must be rounded off. These machine-precision errors make themselves evident in different ways, as discussed in the above examples.

    In order to better understand these round-off errors it’s useful to look at the relative floating-point accuracy provided by the function eps, which quantifies the distance from a given number to the next largest floating-point representation:

    >> eps(1) ans =      2.220446049250313e-16 >> eps(1000) ans =      1.136868377216160e-13 

    Notice that the precision is relative to the size of a given number being represented; larger numbers will have larger distances between floating-point representations, and will thus have fewer digits of precision following the decimal point. This can be an important consideration with some calculations. Consider the following example:

    >> format long              % Display full precision >> x = rand(1, 10);         % Get 10 random values between 0 and 1 >> a = mean(x)              % Take the mean a =    0.587307428244141 >> b = mean(x+10000)-10000  % Take the mean at a different scale, then shift back b =    0.587307428244458 

    Note that when we shift the values of x from the range [0 1] to the range [10000 10001], compute a mean, then subtract the mean offset for comparison, we get a value that differs for the last 3 significant digits. This illustrates how an offset or scaling of data can change the accuracy of calculations performed on it, which is something that has to be accounted for with certain problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to install the LablGL bindings first, as indicated… May 11, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer I would imagine you would have to use the ODBC… May 11, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer I think we're going to resolve this with the following… May 11, 2026 at 9:03 pm

Related Questions

I am writing a fairly large and complex data analysis program and I have
For a program I am writing, I need to ask a user for an
I am writing a program that will draw a solid along the curve of
I am currently working on a project with which I need to program up

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.