Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is 24.0000 not equal to 24.0000 in MATLAB?
    text
    copied!<p>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.</p> <p>In the following code, <code>intersections</code> function gets the intersection points:</p> <pre><code>[points(:,1), points(:,2)] = intersections(... obj.modifiedVGVertices(1,:), obj.modifiedVGVertices(2,:), ... [vertex1(1) vertex2(1)], [vertex1(2) vertex2(2)]); </code></pre> <p>The result:</p> <pre><code>&gt;&gt; points points = 12.0000 15.0000 33.0000 24.0000 33.0000 24.0000 &gt;&gt; vertex1 vertex1 = 12 15 &gt;&gt; vertex2 vertex2 = 33 24 </code></pre> <p>Two points (<code>vertex1</code> and <code>vertex2</code>) should be eliminated from the result. It should be done by the below commands:</p> <pre><code>points = points((points(:,1) ~= vertex1(1)) | (points(:,2) ~= vertex1(2)), :); points = points((points(:,1) ~= vertex2(1)) | (points(:,2) ~= vertex2(2)), :); </code></pre> <p>After doing that, we have this unexpected outcome:</p> <pre><code>&gt;&gt; points points = 33.0000 24.0000 </code></pre> <p>The outcome should be an empty matrix. As you can see, the first (or second?) pair of <code>[33.0000 24.0000]</code> has been eliminated, but not the second one.</p> <p>Then I checked these two expressions:</p> <pre><code>&gt;&gt; points(1) ~= vertex2(1) ans = 0 &gt;&gt; points(2) ~= vertex2(2) ans = 1 % &lt;-- It means 24.0000 is not equal to 24.0000? </code></pre> <p>What is the problem?</p> <hr> <p>More surprisingly, I made a new script that has only these commands:</p> <pre><code>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)), :); </code></pre> <p>The result as expected:</p> <pre><code>&gt;&gt; points points = Empty matrix: 0-by-2 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload