我正在编写一个程序,我需要删除存储在矩阵中的重复点.问题在于,当检查这些点是否在矩阵中时,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)
应从结果中消除两点(vertex1和vertex2).它应该通过以下命令完成:
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) 我有一个for循环遍历一个数组...
for i=1:length(myArray)
Run Code Online (Sandbox Code Playgroud)
在这个循环中,我想检查myArray的值,如果满足某些条件,则将其添加到另一个数组myArray2.我查看了MATLAB文档,但是没有在创建数组时发现任何内容,而没有在初始化时声明所有值或一次性将数据读入其中.
非常感谢!
我想在MATLAB中找到pi,当我把它与已经在MATLAB中体现的pi进行比较时.所以当我写作
while(p~=pi)
Run Code Online (Sandbox Code Playgroud)
循环似乎无穷无尽,因为它一直在测试MATLAB pi所具有的所有数字.
所以当我写道:
p=3.1416;
if p==pi
disp('yes');
else
disp('no');
end
Run Code Online (Sandbox Code Playgroud)
答案自然是否定的.所以我想找到一种方法,在点之后只保留五位数并用它测试,测试pi = 3.14159.
有人可以帮忙吗?