我的问题很简单,有没有人知道如何让matlab ginput忽略后续点击在同一位置?
我已经想到了一些可能性,比如for循环检查存储的数组是否有相同的值并删除它们,但是我遇到了for循环长度的麻烦(因为数组通过删除来改变大小东西),所以这不起作用。我想应该有一些简单的解决方法,但我还没能找到一个......
答案 0 :(得分:2)
简单的代码,但用户努力版本更多
%%// Tolerance
TOL = 5;
%%// Start selecting points for an unlimited number, until Return key is pressed
[x y ] = ginput;
xy = [x y];
xy(sum(abs(diff([x y])),2)<TOL,:) = []; %%// Remove the "nearby points"
天真且更安全的方法
%%// Tolerance
TOL = 5;
%%// Number of points to be clicked
N = 4;
%%// Clicked points array to be stored here
xy_all = zeros(N,2);
%%// First point
[x y ] = ginput(1);
cmp1 = [x y];
xy_all(1,:) = [x y];
%%// Second point onwards
k=2;
while k<=N
[x y ] = ginput(1);
if sum(sum(abs([x y]-cmp1)))>TOL
cmp1 = [x y];
xy_all(k,:) = [x y];
k= k+1;
end
end