相关疑难解决方法(0)

为什么在MATLAB中24.0000不等于24.0000?

我正在编写一个程序,我需要删除存储在矩阵中的重复点.问题在于,当检查这些点是否在矩阵中时,MATLAB不能在矩阵中识别它们,尽管它们存在.

在以下代码中,intersections函数获取交集点:

[points(:,1), points(:,2)] = intersections(...
    obj.modifiedVGVertices(1,:), obj.modifiedVGVertices(2,:), ...
    [vertex1(1) vertex2(1)], [vertex1(2) vertex2(2)]);
Run Code Online (Sandbox Code Playgroud)

结果:

>> points
points =
   12.0000   15.0000
   33.0000   24.0000
   33.0000   24.0000

>> vertex1
vertex1 =
    12
    15

>> vertex2    
vertex2 =
    33
    24
Run Code Online (Sandbox Code Playgroud)

应从结果中消除两点(vertex1vertex2).它应该通过以下命令完成:

points = points((points(:,1) ~= vertex1(1)) | (points(:,2) ~= vertex1(2)), :);
points = points((points(:,1) ~= vertex2(1)) | (points(:,2) ~= vertex2(2)), :);
Run Code Online (Sandbox Code Playgroud)

在这之后,我们有了这个意想不到的结果:

>> points
points =
   33.0000   24.0000
Run Code Online (Sandbox Code Playgroud)

结果应该是一个空矩阵.如你所见,第一对(或第二对)[33.0000 24.0000]已被淘汰,但不是第二对.

然后我检查了这两个表达式:

>> points(1) ~= vertex2(1)
ans …
Run Code Online (Sandbox Code Playgroud)

floating-point precision matlab

67
推荐指数
4
解决办法
2万
查看次数

标签 统计

floating-point ×1

matlab ×1

precision ×1